Submission #564705

#TimeUsernameProblemLanguageResultExecution timeMemory
564705SSRSThree Friends (BOI14_friends)C++14
100 / 100
53 ms7096 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; string U; cin >> U; if (N % 2 == 0){ cout << "NOT POSSIBLE" << endl; } else { int L1 = 0; while (L1 < (N - 1) / 2){ if (U[L1] == U[L1 + (N + 1) / 2]){ L1++; } else { break; } } int R1 = (N - 1) / 2; while (R1 >= 0){ if (U[R1] == U[R1 + (N - 1) / 2]){ R1--; } else { break; } } int L2 = (N - 1) / 2; while (L2 < N){ if (U[L2] == U[L2 - (N - 1) / 2]){ L2++; } else { break; } } int R2 = N - 1; while (R2 >= (N + 1) / 2){ if (U[R2] == U[R2 - (N + 1) / 2]){ R2--; } else { break; } } if (L1 >= R1 && L2 >= R2){ if (U.substr(0, (N - 1) / 2) == U.substr((N + 1) / 2)){ cout << U.substr(0, (N - 1) / 2) << endl; } else { cout << "NOT UNIQUE" << endl; } } else if (L1 >= R1){ cout << U.substr((N + 1) / 2) << endl; } else if (L2 >= R2){ cout << U.substr(0, (N - 1) / 2) << endl; } else { cout << "NOT POSSIBLE" << endl; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...