QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#95759#5577. AlchemyUsername#WA 2ms3668kbC++20852b2023-04-11 20:22:182023-04-11 20:22:21

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-11 20:22:21]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3668kb
  • [2023-04-11 20:22:18]
  • 提交

answer

#include <bits/stdc++.h>

#define el '\n'

typedef long long ll;
typedef long double ld;

#define Beevo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 100 + 5;

int n;
string s;
int dp[N][N][2];

int solve(int l, int r, bool ch) {
    if (l >= r)
        return 0;

    int &ret = dp[l][r][ch];

    if (~ret)
        return ret;

    ret = solve(l + 1, r - 1, 1) + 1;

    ret = min(ret, solve(l + 2, r - 2, 0) + 2);

    if (ch && s[l] != s[r] || !ch && s[l] == s[r])
        ret = min(ret, solve(l + 1, r - 1, 0));

    return ret;
}

void testCase() {
    cin >> s;

    n = s.size();

    memset(dp, -1, sizeof dp);

    cout << solve(0, n - 1, 0);
}

signed main() {
    Beevo

    int t = 1;
//    cin >> t;

    while (t--)
        testCase();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

ioi

output:

0

result:

ok single line: '0'

Test #2:

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

input:

noi

output:

1

result:

ok single line: '1'

Test #3:

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

input:

ctsc

output:

1

result:

ok single line: '1'

Test #4:

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

input:

fool

output:

2

result:

ok single line: '2'

Test #5:

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

input:

vetted

output:

2

result:

ok single line: '2'

Test #6:

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

input:

aa

output:

0

result:

ok single line: '0'

Test #7:

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

input:

ic

output:

1

result:

ok single line: '1'

Test #8:

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

input:

tlffohemdcncrfrxaqsbzcoyodvbxmhqukvfpahnakexcmacqa

output:

12

result:

ok single line: '12'

Test #9:

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

input:

qrgld

output:

1

result:

ok single line: '1'

Test #10:

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

input:

ejyfprguvwrnrsrykyrotmdjuzroohvlxqhvyeukkvmshtpczyyecpzhsqvkxueqvhlxldhofrzcjdhtotykgrsdnrnvuyrphyjy

output:

18

result:

wrong answer 1st lines differ - expected: '26', found: '18'