Submission #17600

#TimeUsernameProblemLanguageResultExecution timeMemory
17600NamnamseoThree Friends (BOI14_friends)C++98
100 / 100
26 ms3036 KiB
#include <cstdio> char buf[2000010]; int count[26]; int target[26]; int n; int main() { scanf("%d",&n); int i; int len = (n-1)/2; scanf("%s",buf); for(i=0;i<n;++i) count[buf[i]-'A']++; int tmp=0, tmpi; for(i=0;i<26;++i){ if(count[i]%2) ++tmp, tmpi=i; } if(tmp!=1){ puts("NOT POSSIBLE"); return 0; } tmp=0; for(i=0;i<26;++i){ target[i]=(count[i]+1)/2; if(target[i]) ++tmp; } int zeroc=0; for(i=0;i<len;++i){ --target[buf[i]-'A']; if(target[buf[i]-'A']==0) zeroc++; } bool a1, a2; int j; bool flag=false; for(i=0, j=len+1; j<n; ++i, ++j){ if(buf[i+flag]!=buf[j]){ if(flag) break; else flag=true; } } a1=(j==n); flag=false; for(i=0,j=len;i<len; ++i, ++j){ if(buf[i]!=buf[j+flag]){ if(flag) break; else flag=true; } } a2=(i==len); if(a1 && a2){ for(i=0;i<len;i++){ if(buf[i]!=buf[i+len+1]) break; } if(i==len) { puts(buf+len+1); } else puts("NOT UNIQUE"); } else if(a1){ puts(buf+len+1); } else if(a2){ buf[len]=0; puts(buf); } else { puts("NOT POSSIBLE"); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...