Submission #938294

#TimeUsernameProblemLanguageResultExecution timeMemory
938294UmairAhmadMirzaThree Friends (BOI14_friends)C++17
0 / 100
96 ms46292 KiB
#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; } bool b=0; for(int i=1;i<n;i++) if(s[i]!=s[i-1]) b=1; pre(); make_Hash(); int rem=0; int cnt=0; for(int i=1;i<=n;i++){ if(org_Hash1(i)==org_Hash2(i)){ rem=i; cnt++; } } if(cnt==0) cout<<"NOT POSSIBLE"<<endl; else if(cnt>1 && b) cout<<"NOT UNIQUE"<<endl; else cout<<make_str(rem)<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...