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>
#define maxn (int)(1e5+51)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define ll long long
#define pb push_back
#define ull unsigned long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define inf 2000000001
#define mod 1000000007 //998244353
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
string s;
int main(){_
int n;cin>>n;
if(!(n&1)){
cout<<"NOT POSSIBLE"<<endl;
return 0;
}
cin>>s;
int pr=0,suf=n/2,ans1=-1,ans2=-2;
while(pr<n/2&&s[pr]==s[pr+(n+1)/2])pr++;
while(suf>0&&s[suf]==s[suf+n/2])suf--;
suf = max(0,suf), pr = min(n/2-1,pr);
// cout<<suf<<" "<<pr<<endl;
if(suf<pr){
cout<<"NOT UNIQUE"<<endl;
return 0;
}else if(suf==pr)ans1 = suf;
pr = 0, suf = n/2-1;
while(pr<n/2&&s[pr]==s[pr+n/2])pr++;
while(suf>=0&&s[suf]==s[suf+(n+1)/2])suf--;
suf = max(0,suf), pr = min(n/2-1,pr);
// cout<<suf<<" "<<pr<<endl;
if(suf<pr){
cout<<"NOT UNIQUE"<<endl;
return 0;
}else if(suf==pr)ans2=suf;
if(ans1==ans2)for(int i=0;i<n/2;++i)cout<<s[i];
else if(ans1!=-1&&ans2!=-2)cout<<"NOT UNIQUE"<<endl;
else if(ans1!=-1)for(int i=n/2+1;i<n;++i)cout<<s[i];
else if(ans2!=-2)for(int i=0;i<n/2;++i)cout<<s[i];
else cout<<"NOT POSSIBLE"<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |