#include <stdio.h>
#include <string.h>
#define N 20000
#define L 10
#define N_ (2 + N * L)
#define A 26
int main() {
static char ss[N][L + 1], used[N_];
static int ll[N], tt[N_][A], kk[N_];
int n, n_, h, h_, i, t, ans;
scanf("%d", &n);
n_ = 2;
for (i = 0; i < n; i++) {
scanf("%s", ss[i]), ll[i] = strlen(ss[i]);
for (h = 0, t = 1; h < ll[i]; h++) {
int a = ss[i][h] - 'a';
if (!tt[t][a])
tt[t][a] = n_++;
t = tt[t][a];
}
kk[t]++;
}
ans = 0;
for (i = 0; i < n; i++) {
for (h = 0; h < ll[i]; h++)
for (h_ = h, t = 1; h_ < ll[i]; h_++) {
t = tt[t][ss[i][h_] - 'a'];
if (!used[t])
ans += kk[t], used[t] = 1;
}
for (h = 0; h < ll[i]; h++)
for (h_ = h, t = 1; h_ < ll[i]; h_++) {
t = tt[t][ss[i][h_] - 'a'];
used[t] = 0;
}
}
ans -= n;
printf("%d\n", ans);
return 0;
}
Compilation message
lozinke.c: In function 'main':
lozinke.c:14:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
lozinke.c:17:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%s", ss[i]), ll[i] = strlen(ss[i]);
| ^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
288 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
588 KB |
Output is correct |
7 |
Correct |
2 ms |
844 KB |
Output is correct |
8 |
Correct |
3 ms |
1068 KB |
Output is correct |
9 |
Correct |
8 ms |
1996 KB |
Output is correct |
10 |
Correct |
12 ms |
3916 KB |
Output is correct |
11 |
Correct |
11 ms |
3116 KB |
Output is correct |
12 |
Correct |
21 ms |
7432 KB |
Output is correct |
13 |
Correct |
19 ms |
2796 KB |
Output is correct |
14 |
Correct |
18 ms |
7736 KB |
Output is correct |
15 |
Correct |
27 ms |
8128 KB |
Output is correct |
16 |
Correct |
19 ms |
972 KB |
Output is correct |
17 |
Correct |
15 ms |
800 KB |
Output is correct |
18 |
Correct |
11 ms |
760 KB |
Output is correct |
19 |
Correct |
19 ms |
5224 KB |
Output is correct |
20 |
Correct |
12 ms |
844 KB |
Output is correct |