QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#139002 | #5577. Alchemy | mojospy | WA | 1ms | 3620kb | C++14 | 657b | 2023-08-12 16:07:30 | 2023-08-12 16:07:32 |
Judging History
answer
#include<iostream>
#include<string>
using namespace std;
char c[27]="zabcdefghijklmnopqrstuvwxy";
string s;
int n;
int same(int l,int r){
//cout<<s<<endl;
if(l<0) return 0;
while(l>=0&&r<n&&s[l]==s[r]){
--l;
++r;
}
if(l==0){
if(l+2==r) return 1;
else return 2;
}
else if(l<0) return 0;
else if(s[l-1]!=s[r+1]) return 1+same(l-2,r+2);
else{
s[r+1]=c[s[r+1]-'a'];
int p1=1+same(l-1,r+1);
s[r+1]=s[l-1];
int p2=2+same(l-1,r+1);
if(l+1==r) --p2;
return min(p1,p2);
}
return 0;
}
int main(){
cin>>s;
n=s.size();
if(n&1) cout<<same(n/2-1,n/2+1);
else cout<<same(n/2-1,n/2);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3620kb
input:
ioi
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3456kb
input:
noi
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
ctsc
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
fool
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3404kb
input:
vetted
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3440kb
input:
aa
output:
0
result:
ok single line: '0'
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 3512kb
input:
ic
output:
2
result:
wrong answer 1st lines differ - expected: '1', found: '2'