Submission #144786

#TimeUsernameProblemLanguageResultExecution timeMemory
144786alexandra_udristoiuLozinke (COCI17_lozinke)C++14
100 / 100
82 ms47608 KiB
#include<iostream> #include<cstring> using namespace std; int n, i, sol, m, j; char s[15]; struct trie{ int nr, nrt, lst; trie *f[26]; trie(){ nr = nrt = lst = 0; for(int i = 0; i < 26; i++){ f[i] = NULL; } } }; trie *r; void adaug(trie *r, char *s, int ok){ if(*s == 0){ if(ok == 1){ sol += r->nr - 1; r->nrt++; } return; } if(r->f[*s - 'a'] == NULL){ r->f[*s - 'a'] = new trie; } if(r->f[*s - 'a']->lst != i){ r->f[*s - 'a']->lst = i; r->f[*s - 'a']->nr++; sol += r->f[*s - 'a']->nrt; } adaug(r->f[*s - 'a'], s + 1, ok); } int main(){ r = new trie; cin>> n; for(i = 1; i <= n; i++){ cin>> s + 1; m = strlen(s + 1); adaug(r, s + 1, 1); for(j = 2; j <= m; j++){ adaug(r, s + j, 0); } } cout<< sol; }

Compilation message (stderr)

lozinke.cpp: In function 'int main()':
lozinke.cpp:39:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         cin>> s + 1;
               ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...