This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |