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;
string s;
int n;
int ans = 0;
void no(){
cout << "NOT POSSIBLE";
exit(0);
}
int l[5000005],r[5000005], ansPOS;
vector <int> poss;
void check(){
for(int i=n/2;i<n-1;i++){
if (s[i-n/2] == s[i]) l[i] = l[i-1] + 1;
else l[i] = - (int)1e9;
}
for(int i=n-1;i>n/2;i--)
if (s[i-n/2-1] == s[i]) r[i] = r[i+1] + 1;
else r[i] = - (int) 1e9;
for(int i=n/2;i<n;i++){
if (l[i-1] + r[i+1] == n/2) ans++, ansPOS = i, poss.push_back(i);
}
for(int i=0;i<n/2;i++){
if (s[i] == s[i+n/2+1]) l[i] = (i ? l[i-1] : 0) + 1;
else l[i] = -(int) 1e9;
}
r[n/2+1] = 0;
for(int i=n/2;i>=1;i--){
if (s[i] == s[i+n/2]) r[i] = r[i+1] + 1;
else r[i] = -(int) 1e9;
}
for(int i=0;i<n/2;i++){
if ((i?l[i-1]:0) + r[i+1] == n/2) ans++, ansPOS = i, poss.push_back(i);
}
}
int main(){
iostream::sync_with_stdio(0);
cin >> n >> s;
if (n%2==0) no();
check();
int cnt = 0;
if (!ans) no();
else{
bool ok = 1;
sort(poss.begin(),poss.end());
for(int i=0;i<(int)poss.size()-1;i++){
if (abs(poss[i]-poss[i+1]) != 1 || s[poss[i]]!=s[poss[i+1]]) ok = 0;
}
if (!ok) cout << "NOT UNIQUE";
else{
for(int i=0;i<n;i++) if (cnt<n/2 && i != ansPOS) cnt++, cout << s[i];
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |