# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
914703 | racsosabe | Lozinke (COCI17_lozinke) | C++14 | 12 ms | 9564 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<bits/stdc++.h>
using namespace::std;
const int N = 20000 + 5;
const int L = 12;
const int SUML = 20000 * 10 + 5;
const int E = 26;
int n;
int len[N];
char s[N][L];
int nodes = 1;
int frec[SUML];
bool vis[SUML];
int trie[E][SUML];
void insert(int id) {
int pos = 0;
for(int i = 0; i < len[id]; i++) {
int c = s[id][i] - 'a';
if(trie[c][pos] == 0) trie[c][pos] = nodes++;
pos = trie[c][pos];
}
frec[pos] += 1;
}
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%s", s[i]);
len[i] = strlen(s[i]);
insert(i);
}
long long res = 0;
for(int id = 1; id <= n; id++) {
for(int i = 0; i < len[id]; i++) {
int pos = 0;
for(int j = i; j < len[id]; j++) {
int c = s[id][j] - 'a';
if(trie[c][pos] == 0) break;
pos = trie[c][pos];
if(not vis[pos]) {
res += frec[pos];
vis[pos] = true;
}
}
}
for(int i = 0; i < len[id]; i++) {
int pos = 0;
for(int j = i; j < len[id]; j++) {
int c = s[id][j] - 'a';
if(trie[c][pos] == 0) break;
pos = trie[c][pos];
vis[pos] = false;
}
}
res -= 1;
}
printf("%lld\n", res);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |