QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#95739#5577. AlchemyUsername#WA 2ms3672kbC++201.8kb2023-04-11 19:11:382023-04-11 19:11:49

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-11 19:11:49]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3672kb
  • [2023-04-11 19:11:38]
  • Submitted

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;


#define ElGed_Sevawy  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define ld long double
#define el '\n'
#define pi acos(-1)
#define F first
#define S second
#define sz(x) (int)(x).size()

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
ll rand(ll l, ll r){
    return uniform_int_distribution<ll>(l, r)(gen);
}

const ll N = 1e2 + 5, M = 1e6 + 5, MOD1 = 1e9 + 7, MOD2 = 1e9 + 9, K = 21, INF  = 2e18 + 5, P1 = 29, P2 = 31;
string s;
int dp[N][N][2], n;
int solve(int l, int r, bool chng){
    if(l >= r) return 0;
    int &ret = dp[l][r][chng];
    if(~ret) return ret;

    ret = 0;
    if(chng){
       if(s[l + 1] == s[r - 1] && l + 1 != r - 1)
           ret = min(2 + solve(l + 2, r - 2, 0), 1 + solve(l + 1, r - 1, 1));
       else ret = 1 + solve(l + 2, r - 2, 0);
    }else{
        if(s[l] == s[r]) ret = solve(l + 1, r - 1, 0);
        else {
            if (s[l + 1] == s[r - 1] && l + 1 != r - 1) ret = min(2 + solve(l + 2, r - 2, 0), 1 + solve(l + 1, r - 1, 1));
            else ret = 1 + solve(l + 2, r - 2, 0);
        }
    }
    return ret;
}
void go() {
    cin >> s;
    n = sz(s);
    memset(dp, -1, sizeof(dp));
    cout << solve(0, n - 1, 0);
}
int32_t main() {
    ElGed_Sevawy
    int tc = 1;
    //cin >> tc;
    while (tc--)
        go();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3492kb

input:

ioi

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3672kb

input:

noi

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3512kb

input:

ctsc

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3448kb

input:

fool

output:

2

result:

ok single line: '2'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3448kb

input:

vetted

output:

2

result:

ok single line: '2'

Test #6:

score: 0
Accepted
time: 2ms
memory: 3496kb

input:

aa

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 2ms
memory: 3496kb

input:

ic

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3492kb

input:

tlffohemdcncrfrxaqsbzcoyodvbxmhqukvfpahnakexcmacqa

output:

12

result:

ok single line: '12'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3460kb

input:

qrgld

output:

1

result:

ok single line: '1'

Test #10:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

ejyfprguvwrnrsrykyrotmdjuzroohvlxqhvyeukkvmshtpczyyecpzhsqvkxueqvhlxldhofrzcjdhtotykgrsdnrnvuyrphyjy

output:

26

result:

ok single line: '26'

Test #11:

score: 0
Accepted
time: 2ms
memory: 3672kb

input:

xcpccpcy

output:

2

result:

ok single line: '2'

Test #12:

score: 0
Accepted
time: 2ms
memory: 3504kb

input:

abpccpcp

output:

1

result:

ok single line: '1'

Test #13:

score: 0
Accepted
time: 1ms
memory: 3648kb

input:

ixpccpci

output:

2

result:

ok single line: '2'

Test #14:

score: 0
Accepted
time: 2ms
memory: 3492kb

input:

xcxccpci

output:

2

result:

ok single line: '2'

Test #15:

score: 0
Accepted
time: 2ms
memory: 3620kb

input:

xcpxcpci

output:

3

result:

ok single line: '3'

Test #16:

score: 0
Accepted
time: 2ms
memory: 3652kb

input:

ixxccpci

output:

1

result:

ok single line: '1'

Test #17:

score: 0
Accepted
time: 2ms
memory: 3668kb

input:

ixpxcpci

output:

2

result:

ok single line: '2'

Test #18:

score: 0
Accepted
time: 0ms
memory: 3516kb

input:

ixpxxycpci

output:

3

result:

ok single line: '3'

Test #19:

score: -100
Wrong Answer
time: 2ms
memory: 3504kb

input:

yxxxyxxxxxyyxxyxxyxyyyxyxyyyyxyxxxxxxxxxxxxyyxxyxyxyyxxyyxyxxyyxxyyyyyyxxyyxxyyxxxxyyyxxxyyxyxyxxyxx

output:

21

result:

wrong answer 1st lines differ - expected: '19', found: '21'