Submission #548521

#TimeUsernameProblemLanguageResultExecution timeMemory
548521krit3379Three Friends (BOI14_friends)C++17
0 / 100
170 ms36480 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]; 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)cnt++,ans=mid; if((hx[mid]-hx[1]*po[mid-1]%mod+mod)%mod==(hx[n]-hx[mid]*po[n-mid]%mod+mod)%mod)cnt++,ans=1; if(hx[mid-1]==(hx[n-1]-hx[mid-1]*po[n-mid]%mod+mod)%mod)cnt++,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)cnt++,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)cnt++,ans=i; } if(cnt==0)printf("NOT POSSIBLE"); else if(cnt>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:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %s",&n,s+1);
      |     ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...