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;
int main(){
int m;cin>>m;
if(m%2==0||m==1){
cout<<"NOT POSSIBLE";
return 0;
}
string a;
cin>>a;
int n=m/2;
int cmn=0;
for(int i = n ; i >= 0 ; i -- )
if(a[i]==a[n+i])cmn++;
else break;
int rez=0;
int ps;
if(cmn>=n){
rez++;
ps=0;
}
for(int i = 0 ; i <= n ; i ++){
if(a[i]!=a[n+1+i])break;
if(i+1+cmn>=n){
rez++;
if(rez==1)
ps=i+1;
else{
cout<<"NOT UNIQUE";
return 0;
}
}
}
cmn=0;
for(int i = n-1 ; i >= 0 ; i -- )
if(a[i]==a[n+1+i])cmn++;
else break;
if(cmn>=n){
rez++;
if(rez==1){
ps=n;
}else{
cout<<"NOT UNIQUE";
return 0;
}
}
for(int i = 0 ; i <= n ; i ++){
if(a[i]!=a[n+i])break;
if(i+1+cmn>=n){
rez++;
if(rez==1)
ps=i+1;
else{
cout<<"NOT UNIQUE";
return 0;
}
}
}
if(rez){
if(ps<=n){
cout<<a.substr(n+1);
}else{
cout<<a.substr(0,n);
}
}else{
cout<<"NOT POSSIBLE";
return 0;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |