Submission #105693

#TimeUsernameProblemLanguageResultExecution timeMemory
105693samsThree Friends (BOI14_friends)C++14
0 / 100
210 ms7904 KiB
#include <bits/stdc++.h> using namespace std; int n; string u; map<char, int> ct; int main() { cin >> n >> u; if(n % 2 == 0) { cout << "NOT POSSIBLE\n"; return 0; } for(auto x: u) ct[x]++; int I = 0; char rep = '.'; for(auto x: ct) if(x.second % 2) I++, rep = x.first; if(I > 1) { cout << "NOT POSSIBLE\n"; return 0; } int mid = (n-1)/2; string s1, s2; int ok = 2; int id = -1; for(int i = 0 ; i < mid ; ++i) s1.push_back(u[i]); for(int i = mid ; i < n ; ++i) s2.push_back(u[i]); for(int i = 0, j = 0, k = 0; i < mid ; ++j, ++i) { if(s1[i] != s2[j]) { if(k == 0 && s1[i] == s2[j+1]) id = j, j++, k = 1; else { ok--; id = -1; break; } } } s1.clear(); s2.clear(); for(int i = 0 ; i <= mid ; ++i) s2.push_back(u[i]); for(int i = mid + 1 ; i < n ; ++i) s1.push_back(u[i]); /* for(int i = 0 ; i < s2.size() ; ++i) cout << s2[i]; cout << "\n"; for(int i = 0 ; i < s1.size() ; ++i) cout << s1[i]; */ for(int i = 0, j = 0, k = 0; i < mid ; ++j, ++i) { if(s1[i] != s2[j]) { if(k == 0 && s1[i] == s2[j+1]) id = j, j++, k = 1; else { ok--; id = -1; break; } } } if(ok == 0) cout << "NOT POSSIBLE\n"; else if(ok == 1 || ct[rep] == n) { if(id <= mid && id != -1) mid++; for(int i = 0 ; i < mid ; ++i) if(i != id) cout << u[i]; cout << "\n"; }else cout << "NOT UNIQUE\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...