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 TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
const int mxN = 2e6+5;
int N, cnt;
string S, a1, a2;
string solve() {
int m = N/2, l = -1, r = m+1, ok;
ok = 1;
FOR(i,0,m-1){
ok &= S[i] == S[i+m+1];
if (ok) l = i;
else break;
}
ok = 1;
RFOR(i,m,0){
ok &= S[i] == S[i+m];
if (ok) r = i;
else break;
}
TRACE(l _ r);
if (l+2 >= r) return S.substr(m+1,N-m-1);
return "";
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> N >> S;
a1 = solve();
reverse(ALL(S));
a2 = solve();
reverse(ALL(a2));
if (!SZ(a1) && !SZ(a2)) cout << "NOT POSSIBLE" << '\n';
else if (SZ(a1) && SZ(a2) && a1 != a2) cout << "NOT UNIQUE" << '\n';
else cout << (SZ(a1) ? a1 : a2) << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |