Submission #105695

#TimeUsernameProblemLanguageResultExecution timeMemory
105695samsThree Friends (BOI14_friends)C++14
100 / 100
96 ms9192 KiB
#include <bits/stdc++.h> using namespace std; int n; string u, a, b, s1, s2; int main() { cin >> n >> u; if(n%2 == 0) { cout << "NOT POSSIBLE\n"; return 0; } int mid = (n-1)/2, p1 = -1, p2 = -1; bool ok1 = true, ok2 = true; for(int i = 0 ; i < mid ; ++i) a.push_back(u[i]); for(int i = mid ; i < n ; ++i) b.push_back(u[i]); for(int i = 0, j = 0; i < mid ; ++j, ++i) { if(a[i] != b[j]) { if(p1 == -1 && a[i] == b[++j]) p1 = j; else { ok1 = false; break; } } s1 += a[i]; } a.clear(); b.clear(); for(int i = 0 ; i <= mid ; ++i) b.push_back(u[i]); for(int i = mid + 1 ; i < n ; ++i) a.push_back(u[i]); for(int i = 0, j = 0; i < mid ; ++j, ++i) { if(a[i] != b[j]) { if(p2 == -1 && a[i] == b[++j]) p2 = j; else { ok2 = false; break; } } s2 += a[i]; } if(!ok1 && !ok2) cout << "NOT POSSIBLE\n"; else { if(ok1 && ok2 && s1 != s2) cout << "NOT UNIQUE\n"; else if(ok1) cout << s1 << "\n"; else cout << s2 << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...