# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
116824 | 2019-06-14T01:52:31 Z | hungcung | Lozinke (COCI17_lozinke) | C++14 | 1000 ms | 1024 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1024 KB | Output is correct |
2 | Correct | 3 ms | 1024 KB | Output is correct |
3 | Correct | 3 ms | 896 KB | Output is correct |
4 | Correct | 18 ms | 1024 KB | Output is correct |
5 | Correct | 94 ms | 896 KB | Output is correct |
6 | Correct | 223 ms | 988 KB | Output is correct |
7 | Correct | 357 ms | 988 KB | Output is correct |
8 | Correct | 403 ms | 896 KB | Output is correct |
9 | Execution timed out | 1086 ms | 896 KB | Time limit exceeded |
10 | Execution timed out | 1083 ms | 896 KB | Time limit exceeded |
11 | Execution timed out | 1072 ms | 896 KB | Time limit exceeded |
12 | Execution timed out | 1078 ms | 896 KB | Time limit exceeded |
13 | Execution timed out | 1088 ms | 896 KB | Time limit exceeded |
14 | Execution timed out | 1074 ms | 896 KB | Time limit exceeded |
15 | Execution timed out | 1084 ms | 896 KB | Time limit exceeded |
16 | Execution timed out | 1077 ms | 896 KB | Time limit exceeded |
17 | Execution timed out | 1084 ms | 896 KB | Time limit exceeded |
18 | Execution timed out | 1086 ms | 896 KB | Time limit exceeded |
19 | Execution timed out | 1075 ms | 1024 KB | Time limit exceeded |
20 | Execution timed out | 1076 ms | 1024 KB | Time limit exceeded |