Submission #15964

#TimeUsernameProblemLanguageResultExecution timeMemory
15964myungwooThree Friends (BOI14_friends)C++14
100 / 100
33 ms5436 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 2000006 int N; char A[MAXN]; int main() { scanf("%d%s", &N, A+1); if (!(N&1)){ puts("NOT POSSIBLE"); return 0; } bool sw = 0; for (int i=1;i<N;i++) if (A[i] != A[N]){ sw = 1; break; } if (!sw){ puts(A+N/2+2); return 0; } int cnt = 0; for (int i=1,j=N/2+1;i<=N/2;i++){ while (j <= N && A[j] != A[i]) j++; if (j <= N && A[j] == A[i]) j++, cnt++; } set <string> S; if (cnt == N/2) S.insert(string(A+1, A+N/2+1)); cnt = 0; for (int i=N/2+2,j=1;i<=N;i++){ while (j <= N/2+1 && A[j] != A[i]) j++; if (j <= N/2+1 && A[j] == A[i]) j++, cnt++; } if (cnt == N/2) S.insert(string(A+N/2+2, A+N+1)); if (S.empty()) puts("NOT POSSIBLE"); else if (S.size() > 1) puts("NOT UNIQUE"); else puts(S.begin()->c_str()); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...