Submission #548523

#TimeUsernameProblemLanguageResultExecution timeMemory
548523krit3379Three Friends (BOI14_friends)C++17
100 / 100
173 ms36496 KiB
#include<bits/stdc++.h> using namespace std; #define N 2000005 long long hx[N],po[N],p=31,cnt,ans,l,r,mod=1e9+7; char s[N]; map<long long,int> mp; int main(){ int n,i,mid; scanf("%d %s",&n,s+1); po[0]=1; for(i=1;i<=n;i++)po[i]=po[i-1]*p%mod; for(i=1;i<=n;i++)hx[i]=(hx[i-1]*p+s[i]-'A'+1)%mod; mid=(n+1)/2; if(hx[mid-1]==(hx[n]-hx[mid]*po[n-mid]%mod+mod)%mod)mp[hx[mid-1]],ans=mid; if((hx[mid]-hx[1]*po[mid-1]%mod+mod)%mod==(hx[n]-hx[mid]*po[n-mid]%mod+mod)%mod)mp[(hx[mid]-hx[1]*po[mid-1]%mod+mod)%mod],ans=1; if(hx[mid-1]==(hx[n-1]-hx[mid-1]*po[n-mid]%mod+mod)%mod)mp[hx[mid-1]],ans=n; for(i=2;i<mid;i++){ l=(hx[i-1]*po[mid-i]%mod+hx[mid]-hx[i]*po[mid-i]%mod+mod)%mod; r=(hx[n]-hx[mid]*po[n-mid]%mod+mod)%mod; if(l==r)mp[l],ans=i; } for(i=mid+1;i<n;i++){ l=hx[mid-1]; r=((hx[i-1]-hx[mid-1]*po[i-mid]%mod+mod)%mod*po[n-i]%mod+(hx[n]-hx[i]*po[n-i]%mod+mod)%mod)%mod; if(l==r)mp[l],ans=i; } if(mp.size()==0)printf("NOT POSSIBLE"); else if(mp.size()>1)printf("NOT UNIQUE"); else{ for(i=1,cnt=0;cnt<mid-1;i++)if(i!=ans)printf("%c",s[i]),cnt++; } return 0; }

Compilation message (stderr)

friends.cpp: In function 'int main()':
friends.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d %s",&n,s+1);
      |     ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...