QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#731398 | #5577. Alchemy | jkliao# | WA | 0ms | 3732kb | C++17 | 627b | 2024-11-10 03:15:13 | 2024-11-10 03:15:13 |
Judging History
answer
#include <iostream>
#include <vector>
using namespace std;
int main() {
string t; cin >> t;
int n = t.length();
vector<char> s(n+2);
for (int i = 1; i <= n; i++) {
s[i] = t[i-1];
}
vector<int> dp(n+2, 1e9);
dp[0] = 0;
for (int i = 1; i <= n/2 + 1; i++) {
if (s[i] == s[n-i+1]) {
dp[i] = min(dp[i], dp[i-1]);
}
if (i >= 2) {
if ((s[i] != s[n-i+1] && s[i-1] != s[n-i+2]) || i == n/2 + 1) {
dp[i] = min(dp[i], 1 + dp[i-2]);
}
else {
dp[i] = min(dp[i], 2 + dp[i-2]);
}
}
}
/*
for (int i = 0; i <= n; i++) {
cout << dp[i] << ' ';
}
cout << endl;
*/
cout << dp[n/2 + 1] << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
ioi
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
noi
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3460kb
input:
ctsc
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
fool
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
vetted
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
aa
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3464kb
input:
ic
output:
1
result:
ok single line: '1'
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3584kb
input:
tlffohemdcncrfrxaqsbzcoyodvbxmhqukvfpahnakexcmacqa
output:
14
result:
wrong answer 1st lines differ - expected: '12', found: '14'