Submission #938261

#TimeUsernameProblemLanguageResultExecution timeMemory
938261UmairAhmadMirzaThree Friends (BOI14_friends)C++17
0 / 100
1090 ms7116 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int const N=2e3+5; int const mod=1e9+7; 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)+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 i=0; while(st.size()<(n/2)){ if(i==p-1) continue; st+=s[i]; i++; } return st; } signed main() { cin>>n; cin>>s; if(n%2==0){ cout<<"NOT POSSIBLE\n"; return 0; } 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) cout<<"NOT UNIQUE"<<endl; else cout<<make_str(rem)<<endl; return 0; }

Compilation message (stderr)

friends.cpp: In function 'std::string make_str(long long int)':
friends.cpp:42:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   42 |   while(st.size()<(n/2)){
      |         ~~~~~~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...