Submission #116824

#TimeUsernameProblemLanguageResultExecution timeMemory
116824hungcungLozinke (COCI17_lozinke)C++14
40 / 100
1088 ms1024 KiB
#include<bits/stdc++.h> using namespace std; int n,dem; string s[20005],s1,s2; const long long mod=1e9+7,base=31; long long pOw[15],hAsH[15]; long long getHash(long long i,long long j){ return(hAsH[j]-hAsH[i-1]*pOw[j-i+1]+mod*mod)%mod; } int main(){ scanf("%d",&n); for(int i=0;i<n;i++){ cin>>s[i]; } int ans=0; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ int leni=s[i].length(),lenj=s[j].length(),ktra=0; bool check=false; if(leni<lenj){ s2=s[i]; s1=s[j]; leni=s1.length(); lenj=s2.length(); }else if(leni>=lenj){ s1=s[i]; s2=s[j]; } pOw[0]=1ll; s1=" "+s1; for(int k=1;k<=leni;k++){ pOw[k]=pOw[k-1]*base%mod; }for(int k=1;k<=leni;k++){ hAsH[k]=(hAsH[k-1]*base+s1[k]-'a'+1)%mod; } s2=" "+s2; for(int k=1;k<=lenj;k++){ ktra=(ktra*base+s2[k]-'a'+1)%mod; }for(int k=1;k<=leni-lenj+1;k++){ if(ktra==getHash(k,k+lenj-1)){ check=true; break; } } if(check==true){ if(leni==lenj) ans+=2; else ans++; } } } printf("%d",ans); }

Compilation message (stderr)

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