-
-
Save harurunrunrun/3ab33fa147410578f05094913986fd8c to your computer and use it in GitHub Desktop.
ICPC模擬国内予選2021 D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
using ll=long long; | |
string S; | |
void solve(){ | |
int N=S.size(); | |
ll ans=0; | |
for(int i=0;i<N/2;i++){ | |
if(S.at(i)==S.at(N-i-1)){ | |
continue; | |
} | |
bool c=true; | |
for(int j=i;j<N-i-1;j++){ | |
if(S.at(j)==S.at(N-i-1)){ | |
int l=j-i+1; | |
bool f=true; | |
for(int k=0;k<l;k++){ | |
if(S.at(i+k)!=S.at(N-i-l+k)){ | |
f=false; | |
break; | |
} | |
} | |
if(f){ | |
c=false; | |
ans+=l*l; | |
for(int k=0;k<l;k++){ | |
S.at(i+k)=S.at(N-i-1-k); | |
} | |
break; | |
} | |
} | |
} | |
if(c){ | |
cout<<-1<<endl; | |
return; | |
} | |
} | |
cout<<ans<<endl; | |
return; | |
} | |
int main(){ | |
while(true){ | |
cin>>S; | |
if(S=="#"){ | |
break; | |
} | |
solve(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment