이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |