QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#753473 | #5577. Alchemy | anyan26 | WA | 0ms | 3836kb | C++17 | 1.2kb | 2024-11-16 13:03:24 | 2024-11-16 13:03:25 |
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;
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: 3552kb
input:
ioi
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
noi
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3836kb
input:
ctsc
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'