# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
144786 | alexandra_udristoiu | Lozinke (COCI17_lozinke) | C++14 | 82 ms | 47608 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |