제출 #396705

#제출 시각아이디문제언어결과실행 시간메모리
396705Alma세 명의 친구들 (BOI14_friends)C++14
0 / 100
23 ms6128 KiB
#include <bits/stdc++.h> using namespace std; bool same (string & s) { if ((int)s.size() == 1) return false; for (int i = 1; i < (int)s.size(); i++) { if (s[i-1] != s[i]) return false; } return true; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; string s; cin >> s; if (n % 2 == 0) { cout << "NOT POSSIBLE\n"; return 0; } // left: bool left = true, l = true; int a = 0, b = n/2; string leftPart = ""; while (a < n/2 && b < n) { if (s[a] != s[b]) { if (l) { b++; l = false; } else { left = false; } } leftPart += s[a]; a++; b++; } // right: bool right = true, r = true; int c = n/2+1, d = 0; string rightPart = ""; while (c < n && d <= n/2) { if (s[c] != s[d]) { if (r) { d++; r = false; } else { right = false; } } rightPart += s[c]; c++; d++; } if (left && right) { if (leftPart == rightPart && !(same(leftPart))) cout << leftPart << '\n'; else cout << "NOT UNIQUE\n"; } else if (left) { cout << leftPart << '\n'; } else if (right) { cout << rightPart << '\n'; } else { cout << "NOT POSSIBLE\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...