Submission #116821

#TimeUsernameProblemLanguageResultExecution timeMemory
116821ntrung03Lozinke (COCI17_lozinke)C11
30 / 100
1076 ms2432 KiB
#include <stdio.h> #include <string.h> #define int long long #define mod 1204755107 #define base 31 char s[20002][12]; int h[20002][12]; int p[12]; signed main() { int n; scanf("%lld\n",&n); p[0] = 1; for(int i=1;i<12;i++)p[i] = (p[i-1]*base)%mod; int res = 0; for(int i=0;i<n;i++) scanf("%s\n",s[i]); for(int i=0;i<n;i++) { for(int j=0;j<strlen(s[i]);j++) { h[i][j] = (j>0?h[i][j-1]:0); h[i][j] = ((h[i][j]*base)%mod+s[i][j]-'a'+1)%mod; } } for(int i=0;i<n;i++) { int l = strlen(s[i]); for(int j=0;j<n;j++) if(i!=j){ int sz = strlen(s[j]); for(int k = sz-1;k<l;k++){ int l = k-sz+1; int r = k; long long ph = h[i][r]-(l>0?h[i][l-1]*p[r-l+1]:0)%mod; if(ph==h[j][sz-1]){ res++; break; } } } } printf("%lld",res); }

Compilation message (stderr)

lozinke.c: In function 'main':
lozinke.c:11:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld\n",&n);
  ^~~~~~~~~~~~~~~~~~
lozinke.c:15:23: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) scanf("%s\n",s[i]);
                       ^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...