Submission #38480

#TimeUsernameProblemLanguageResultExecution timeMemory
38480WaschbarThree Friends (BOI14_friends)C++14
0 / 100
93 ms7860 KiB
#include <bits/stdc++.h> using namespace std; int cnt[100]; int main() { string s; int n; cin >> n; cin >> s; if(n%2 == 0) { cout << "NOT POSSIBLE"; return 0; } for(int i = 0; i < n; i++) cnt[s[i]-'A']++; char ch; int tmp = 0; for(int i = 0; i < 30; i++) if(cnt[i]%2) tmp++,ch = (char)('A'+i); if(tmp != 1) { cout << "NOT POSSIBLE"; return 0; } int x1, x2, y1, y2; bool ind = 0; x1 = n/2; x2 = n-1; y1 = y2 = -1; while(x1 >= 0 && x2 > n/2) { if(s[x1] != s[x2] && s[x1] == ch){ y1 = x1; if((x1 > 0 && s[x1-1] == ch) || (x1 < n/2 && s[x1+1] == ch)) ind = 1; break; } x1--; x2--; } if(x1 >= 0 && x2 <= n/2 && s[x1] == ch){ y1 = x1; if((x1 > 0 && s[x1-1] == ch) || (x1 < n/2 && s[x1+1] == ch)) ind = 1; } x1 = n/2-1; x2 = n-1; while(x1 >= 0 && x2 >= n/2) { if(s[x1] != s[x2] && s[x2] == ch){ y2 = x2; if((x2 > n/2 && s[x2-1] == ch) || (x2 < n-1 && s[x2+1] == ch)) ind = 1; break; } x1--; x2--; } if(x1 > 0 && x2 <= n/2 && s[x2] == ch){ y2 = x2; if((x2 > n/2 && s[x2-1] == ch) || (x2 < n-1 && s[x2+1] == ch)) ind = 1; } // cout << y1 << " " << y2 << " " << ch << endl; if(y1 == -1 && y2 == -1) { cout << "NOT POSSIBLE"; return 0; } bool b1, b2; b1 = b2 = 0; if(y1 != -1) { x1 = 0; x2 = n/2+1; if(x1 == y1) x1++; while(x1 <= n/2) { if(s[x1] != s[x2]) { b1 = 1; break; } x1++; x2++; if(x1 == y1) x1++; } } if(y2 != -1){ x1 = 0; x2 = n/2; if(x2 == y2) x2++; while(x1 < n/2) { if(s[x1] != s[x2]) { b2 = 1; break; } x1++; x2++; if(x2 == y2) x2++; } } if(y1 != -1 && y2 != -1 && b1 == 1 && b2 == 1) {cout<<"NOT POSSIBLE";return 0;} if(y1 != -1 && y2 == -1 && b1 == 1) {cout<<"NOT POSSIBLE";return 0;} if(y1 == -1 && y2 != -1 && b2 == 1) {cout<<"NOT POSSIBLE";return 0;} if(y1 != y2 && y1 != -1 && y2 != -1) ind = 1; if(ind){ cout <<"NOT UNIQUE"; return 0; } if(y1 != -1) { x1 = 0; x2 = n/2+1; if(x1 == y1) x1++; while(x1 <= n/2) { cout << s[x1]; x1++; x2++; if(x1 == y1) x1++; } } else { x1 = 0; x2 = n/2; if(x2 == y2) x2++; while(x1 < n/2) { cout << s[x2]; x1++; x2++; if(x2 == y2) x2++; } } }

Compilation message (stderr)

friends.cpp: In function 'int main()':
friends.cpp:38:46: warning: 'ch' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if((x1 > 0 && s[x1-1] == ch) || (x1 < n/2 && s[x1+1] == ch)) ind = 1;
                                              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...