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 <iostream>
#include <set>
using namespace std;
#define ll long long
const ll N=2e6+2;
ll pre[N],pw[N],base=379,mod=1e9+9;
int get(int l,int r)// one base indexing 1<=l<=n
{
if(r<l)
return 0;
return ((pre[r]-(pre[l-1]*pw[r-l+1])%mod)%mod+mod)%mod;
}
int main()
{
int n;
cin>>n;
string s;
cin>>s;
pre[0]=0;
pw[0]=1;
for(int i=1;i<=n;i++)
pw[i]=(pw[i-1]*base)%mod;
for(int i=1;i<=n;i++)
pre[i]=((pre[i-1]*base)%mod+(s[i-1]-'A'))%mod;
set<int> posa,pp;
int len=(n-1)/2;
for(int i=1;(n%2==1) and i<=n and posa.size()<2;i++)
{
ll fit=0;
ll sec=0;
int lf=(i-1);
if(lf<=len)
{
fit=((get(1,i-1)*pw[len-lf])%mod+get(i+1,i+len-lf))%mod;
sec=get(i+len-lf+1,n);
}
else{
fit=get(1,len);
sec=((get(len+1,i-1)*pw[n-i])%mod + get(i+1,n))%mod;
}
if(fit==sec)
{
posa.insert(fit);
pp.insert(i);
}
}
if(posa.size()==0 or n%2!=1)
{
cout<<"NOT POSSIBLE\n";
}
else if(posa.size()==1)
{
int j=*begin(pp);
for(int i=1,p=0;p<len;i++)
{
if(i!=j)
{
cout<<s[i-1];
p++;
}
}
cout<<'\n';
}
else{
cout<<"NOT UNIQUE\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |