QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#753481 | #5577. Alchemy | anyan26 | WA | 0ms | 3840kb | C++17 | 1.2kb | 2024-11-16 13:04:29 | 2024-11-16 13:04:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main(){
/*
* ABBA -> dp[0] = 0, dp[1] = 0
* ABCA -> dp[0] = 1, dp[1] = 1
* ABCD -> dp[0] = 1, dp[1] = 2
* ABBC -> dp[0] = 0, dp[1] = 2
*/
/*
* ABA -> dp[0] = 0, dp[1] = 0
* ABC -> dp[0] = 0, dp[1] = 1
* AAB -> dp[0] = 0, dp[1] = 1
* AAA -> dp[-] = 0, dp[1] =0 0
*/
string s; cin >> s;
if(s.size()==2){
cout << !(s[0]==s[1]) << "\n";
}
int center = s.size()/2;
int dp[(s.size()+1)/2];
for(auto & i : dp)i = 0;
int lp = center-3, rp=center+2;
if(s.size()%2==0){
if(s[center]==s[center-1])dp[0] = 0;
else dp[0]=1;
if(s[center-2]!=s[center+1])dp[1] =2;
else dp[1] = dp[0];
}else if(s.size()%2==1){
dp[0] = 0;
if(s[center-1]==s[center+1])dp[1]=0;
else dp[1] = 1;
lp=center-2;
rp=center+2;
}
while(lp>=0){
if(s[lp]==s[rp]){
dp[center-lp]=dp[center-lp-1];
}else{
if(s[lp+1] != s[rp-1]){
dp[rp-center]=dp[rp-center-2]+1;
}else{
dp[rp-center]=dp[rp-center-2]+2;
}
}
lp--; rp++;
}
cout << dp[center-(s.size()%2==0)] << "\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
input:
ioi
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
noi
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
ctsc
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
fool
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
vetted
output:
2
result:
ok single line: '2'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3796kb
input:
aa
output:
0 0
result:
wrong output format Extra information in the output file