Submission #310565

#TimeUsernameProblemLanguageResultExecution timeMemory
310565sofapudenThree Friends (BOI14_friends)C++14
0 / 100
1062 ms8212 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; string s; cin >> s; if(!(n&1)){ cout << "NOT POSSIBLE\n"; return 0; } vector<int> am(26,0); for(int i = 0; i < n; ++i){ am[s[i]-'A']++; } int tot = 0; char c = '?'; for(int i = 0; i < 26; ++i){ if(am[i]&1){tot++;c = 'A'+i;} } if(tot > 1){cout << "NOT POSSIBLE\n"; return 0;} int ans = 0; string ori; string s1, s2; for(int i = 0; i < n; ++i){ if(s[i] == c){ if(i >= n/2){ s1 = s.substr(0,n/2); } else{ s1 = s.substr(0,i); s1+=s.substr(i+1, n/2-i); } if(i <= n/2){ s2 = s.substr(n/2+1,n/2); } else{ s2 = s.substr(n/2,i-n/2); s2+=s.substr(i+1,n/2-(i-n/2)); } if(s1 == s2){ans++;ori = s1;} } if(ans > 1){cout << "NOT UNIQUE\n";return 0;} } if(!ans){cout << "NOT POSSIBLE\n"; return 0;} cout << ori << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...