Submission #535695

#TimeUsernameProblemLanguageResultExecution timeMemory
535695daisyThree Friends (BOI14_friends)C++17
Compilation error
0 ms0 KiB
#include<iostream> #define endl '\n' using namespace std; const unsigned unsigned long long mod=1000000007,base=27,mod2=100000000069,base2=37; unsigned unsigned long long h[2000005],st[2000005],h2[2000005],st2[2000005]; unsigned unsigned long long faststep(unsigned long long n,unsigned long long st) { if(st==0) return 1; if(st==1) return n; if(st%2==0) { unsigned long long r=faststep(n,st/2); return r*r%mod; } else return faststep(n,st-1)*n%mod; } unsigned long long faststep2(unsigned long long n,unsigned long long st) { if(st==0) return 1; if(st==1) return n; if(st%2==0) { unsigned long long r=faststep2(n,st/2); return r*r%mod2; } else return faststep2(n,st-1)*n%mod2; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); unsigned long long n; string s; cin>>n; cin>>s; if(n%2==0) { cout<<"NOT POSSIBLE"<<endl; return 0; } st[0]=1;st2[0]=1; for(int i=1;i<=n;i++) { st[i]=(st[i-1]*base)%mod; st2[i]=(st2[i-1]*base2)%mod2; } h[0]=(s[0]-'A');h2[0]=(s[0]-'A'); for(int i=1;i<n;i++) { h[i]=(h[i-1]+st[i]*(s[i]-'A'))%mod; h2[i]=(h2[i-1]+st2[i]*(s[i]-'A'))%mod2; } unsigned long long brd=n/2,r,re,r2,re2,in=-1; unsigned long long s1=faststep(base,mod-2),s2=faststep(st[brd+1],mod-2),s3=faststep(st[brd],mod-2); unsigned long long s21=faststep2(base2,mod2-2),s22=faststep2(st2[brd+1],mod2-2),s23=faststep2(st2[brd],mod2-2); for(int i=0;i<n;i++) { r=0;re=0;r2=0;re2=0; if(i<=brd) { if(i>0) r+=h[i-1]; r+=((h[brd]-h[i]+mod)%mod*s1)%mod;r%=mod; re=(((h[n-1]-h[brd]+mod)%mod)*s2)%mod; if(i>0) r2+=h2[i-1]; r2+=((h2[brd]-h2[i]+mod2)%mod2*s21)%mod2;r2%=mod2; re2=(((h2[n-1]-h2[brd]+mod2)%mod2)*s22)%mod2; } else if(i>brd) { r=((h[i-1]-h[brd-1]+mod)%mod)*s3%mod; r+=((h[n-1]-h[i]+mod)%mod)*s2%mod; re=h[brd-1]; r2=((h2[i-1]-h2[brd-1]+mod2)%mod2)*s23%mod2; r2+=((h2[n-1]-h2[i]+mod2)%mod2)*s22%mod2; re2=h2[brd-1]; } // cout<<i<<" "<<r<<" "<<re<<" "<<r2<<" "<<re2<<endl; if(r==re && r2==re2) { if(in!=-1) {cout<<"NOT UNIQUE"<<endl;return 0;} in=i; } } if(in==-1) { cout<<"NOT POSSIBLE"<<endl; return 0; } int brb=0; for(int i=0;brb<brd;i++) { if(i==in) continue; brb++; cout<<s[i]; } cout<<endl; }

Compilation message (stderr)

friends.cpp:4:16: error: duplicate 'unsigned'
    4 | const unsigned unsigned long long mod=1000000007,base=27,mod2=100000000069,base2=37;
      |                ^~~~~~~~
      |                --------
friends.cpp:5:10: error: duplicate 'unsigned'
    5 | unsigned unsigned long long h[2000005],st[2000005],h2[2000005],st2[2000005];
      |          ^~~~~~~~
      |          --------
friends.cpp:6:10: error: duplicate 'unsigned'
    6 | unsigned unsigned long long faststep(unsigned long long n,unsigned long long st)
      |          ^~~~~~~~
      |          --------
friends.cpp: In function 'int main()':
friends.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   48 |     for(int i=1;i<=n;i++)
      |                 ~^~~
friends.cpp:54:18: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   54 |     for(int i=1;i<n;i++)
      |                 ~^~
friends.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   64 |     for(int i=0;i<n;i++)
      |                 ~^~
friends.cpp:67:13: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   67 |         if(i<=brd)
      |            ~^~~~~
friends.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   77 |         else if(i>brd)
      |                 ~^~~~
friends.cpp:92:18: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
   92 |             if(in!=-1) {cout<<"NOT UNIQUE"<<endl;return 0;}
      |                ~~^~~~
friends.cpp:96:10: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
   96 |     if(in==-1)
      |        ~~^~~~
friends.cpp:103:20: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
  103 |     for(int i=0;brb<brd;i++)
      |                 ~~~^~~~
friends.cpp:105:13: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
  105 |         if(i==in) continue;
      |            ~^~~~