Submission #106104

#TimeUsernameProblemLanguageResultExecution timeMemory
106104sofhiasouzaThree Friends (BOI14_friends)C++14
100 / 100
123 ms11104 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; int main() { int n, resp1 = 1, resp2 = 1; string s; cin >> n; cin >> s; if(n%2 == 0) { cout << "NOT POSSIBLE\n"; return 0; } int meio = n/2; string a = "", b = "", s1 = "", s2 = ""; for(int i = 0 ; i < n ; i++) { if(i < meio) a.pb(s[i]); else b.pb(s[i]); } int v = -1, j = 0; for(int i = 0 ; i < meio ; i++) { if(a[i] != b[j]) { if(v == -1 and a[i] == b[++j]) v = i; else { resp1 = 0; break; } } s1.pb(a[i]); j++; } v = -1, j = 0; a = "", b = ""; for(int i = 0 ; i < n ; i++) { if(i <= meio) b.pb(s[i]); else a.pb(s[i]); } for(int i = 0 ; i < meio ; i++) { if(a[i] != b[j]) { if(v == -1 and a[i] == b[++j]) v = i; else { resp2 = 0; break; } } s2.pb(a[i]); j++; } if(!resp1 and !resp2) cout << "NOT POSSIBLE\n"; else if((resp1 and !resp2) or (resp1 and resp2 and s1 == s2)) cout << s1 << endl; else if(resp2 and !resp1) cout << s2 << endl; else cout << "NOT UNIQUE\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...