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;
#define int long long
int const N=3e6+5;
int const mod=1e9+9;
int const base=727;
int Hash[N];
int pw[N];
int n;
string s;
void pre(){
pw[0]=1;
for(int i=1;i<N;i++)
pw[i]=(pw[i-1]*base)%mod;
}
void make_Hash(){
for(int i=1;i<=n;i++)
Hash[i]=(((Hash[i-1]*base)%mod)+s[i-1])%mod;
}
int compute_Hash(int l,int r){
return ((Hash[r] - ((Hash[l]*pw[r-l])%mod) )+mod)%mod;
}
int org_Hash1(int e){
if(e>n/2)
return Hash[n/2];
int h=(Hash[e-1]*pw[((n/2)+1)-e])%mod;
h+=compute_Hash(e,(n/2)+1);
h%=mod;
return h;
}
int org_Hash2(int e){
if(e<=(n/2)+1)
return compute_Hash((n/2)+1,n);
int h=(compute_Hash((n/2),e-1)*pw[n-e])%mod;
h+=compute_Hash(e,n);
h%=mod;
return h;
}
string make_str(int p){
string st="";
int sz=0;
int i=0;
while(i<=n && sz<(n/2)){
i++;
if(i==p)
continue;
st+=s[i-1];
sz++;
}
return st;
}
signed main()
{
cin>>n;
cin>>s;
if(n%2==0){
cout<<"NOT POSSIBLE\n";
return 0;
}
pre();
make_Hash();
int rem=0;
vector<int> rm;
int cnt=0;
for(int i=1;i<=n;i++){
if(org_Hash1(i)==org_Hash2(i)){
rem=i;
rm.push_back(i);
cnt++;
}
}
if(cnt==0)
cout<<"NOT POSSIBLE"<<endl;
else if(cnt>1 && make_str(rm[0])!=make_str(rm[1]))
cout<<"NOT UNIQUE"<<endl;
else
cout<<make_str(rem)<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |