QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#401108 | #5577. Alchemy | joelgun14 | WA | 0ms | 3828kb | C++14 | 1.2kb | 2024-04-27 22:03:10 | 2024-04-27 22:03:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
bool correct[n];
for(int i = 0; i < n; ++i) {
if(s[i] == s[n - i - 1])
correct[i] = true;
else
correct[i] = false;
}
if(s.size() <= 3) {
if(correct[0])
cout << 0 << endl;
else
cout << 1 << endl;
return 0;
}
int dp[n][2];
// utk posisi 0
if(correct[0]) {
dp[0][1] = 0;
dp[0][0] = 1e9;
}
else {
dp[0][1] = 1e9;
dp[0][0] = 0;
}
for(int i = 1; i < n / 2; ++i) {
if(correct[i]) {
// SB -> BS -> BB
if(i == n / 2 - 1 && s.size() % 2 == 1) {
dp[i][1] = min(dp[i - 1][1], dp[i - 1][0] + 1);
break;
}
dp[i][1] = min(dp[i - 1][1], dp[i - 1][0] + 2);
// BB -> SS -> BS
// SB -> BS
dp[i][0] = min(dp[i - 1][1] + 2, dp[i - 1][0] + 1);
}
else {
if(i == n / 2 - 1) {
dp[i][1] = min(dp[i - 1][1] + 1, dp[i - 1][0] + 1);
break;
}
dp[i][1] = min(dp[i - 1][1] + 2, dp[i - 1][0] + 1);
dp[i][0] = min(dp[i - 1][1], dp[i - 1][0] + 1);
}
//cout << dp[i][0] << " " << dp[i][1] << endl;
}
cout << dp[n / 2 - 1][1] << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
ioi
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
noi
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
ctsc
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
fool
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
vetted
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
aa
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
ic
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
tlffohemdcncrfrxaqsbzcoyodvbxmhqukvfpahnakexcmacqa
output:
12
result:
ok single line: '12'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
qrgld
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
ejyfprguvwrnrsrykyrotmdjuzroohvlxqhvyeukkvmshtpczyyecpzhsqvkxueqvhlxldhofrzcjdhtotykgrsdnrnvuyrphyjy
output:
26
result:
ok single line: '26'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
xcpccpcy
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
abpccpcp
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
ixpccpci
output:
2
result:
ok single line: '2'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
xcxccpci
output:
2
result:
ok single line: '2'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
xcpxcpci
output:
3
result:
ok single line: '3'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
ixxccpci
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
ixpxcpci
output:
2
result:
ok single line: '2'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
ixpxxycpci
output:
3
result:
ok single line: '3'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
yxxxyxxxxxyyxxyxxyxyyyxyxyyyyxyxxxxxxxxxxxxyyxxyxyxyyxxyyxyxxyyxxyyyyyyxxyyxxyyxxxxyyyxxxyyxyxyxxyxx
output:
19
result:
ok single line: '19'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
caacbbacc
output:
2
result:
ok single line: '2'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
xjnfkxxjfnjx
output:
2
result:
ok single line: '2'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
baabaaa
output:
2
result:
ok single line: '2'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
bbaccaabcabca
output:
3
result:
ok single line: '3'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
ozo
output:
0
result:
ok single line: '0'
Test #25:
score: -100
Wrong Answer
time: 0ms
memory: 3560kb
input:
zoooo
output:
1
result:
wrong answer 1st lines differ - expected: '2', found: '1'