#include <ctype.h>
#include <stdio.h>
#include <string.h>
#define N 100000
#define A 62
#define L 8
#define MD 998244353
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
char *ss[N * 2];
void sort(char **ss, int l, int r) {
while (l < r) {
int i = l, j = l, k = r;
char *s = ss[l + rand_() % (r - l)], *tmp;
while (j < k) {
int c = strcmp(ss[j], s);
if (c == 0)
j++;
else if (c < 0) {
tmp = ss[i], ss[i] = ss[j], ss[j] = tmp;
i++, j++;
} else {
k--;
tmp = ss[j], ss[j] = ss[k], ss[k] = tmp;
}
}
sort(ss, l, i);
l = k;
}
}
int idx(char c) {
return isdigit(c) ? c - '0' : (isupper(c) ? c - 'A' + 10 : c - 'a' + 36);
}
int count(int a, int b, int c, int d) {
if (a == b && b == c && c == d)
return 1;
else if (a == b && b == c || b == c && c == d || c == d && d == a || d == a && a == b)
return 4;
else if (a == b && c == d || a == c && b == d || a == d && b == c)
return 6;
else if (a == b || a == c || a == d || b == c || b == d || c == d)
return 12;
else
return 24;
}
int main() {
static int kk[L][A][A];
static long long kk_[A][A][A];
int n, i, l, a, b, c, d;
long long ans;
scanf("%d", &n);
for (i = 0; i < n; i++) {
static char s[16], t[16];
int h;
scanf("%s", s), l = strlen(s);
for (h = 0; h < l; h++)
t[h] = s[l - 1 - h];
t[l] = 0;
ss[i << 1 | 0] = strdup(s), ss[i << 1 | 1] = strdup(t);
}
sort(ss, 0, n * 2);
for (i = 0; i < n * 2; i++)
if (i == 0 || strcmp(ss[i - 1], ss[i]) != 0) {
l = strlen(ss[i]);
kk[l - 3][idx(ss[i][0])][idx(ss[i][l - 1])]++;
}
ans = 0;
for (l = 0; l < L; l++) {
for (a = 0; a < A; a++)
for (b = a; b < A; b++)
for (c = b; c < A; c++) {
long long k;
k = 0;
for (d = 0; d < A; d++)
k += (long long) kk[l][a][d] * kk[l][b][d] * kk[l][c][d];
kk_[a][b][c] = kk_[a][c][b] = kk_[b][a][c] = kk_[b][c][a] = kk_[c][a][b] = kk_[c][b][a] = k % MD;
}
for (a = 0; a < A; a++)
for (b = a; b < A; b++)
for (c = b; c < A; c++)
for (d = c; d < A; d++)
ans += (long long) kk_[a][b][c] * kk_[b][c][d] % MD * kk_[c][d][a] % MD * kk_[d][a][b] % MD * count(a, b, c, d);
ans %= MD;
}
printf("%lld\n", ans);
return 0;
}
Compilation message
cubeword.c: In function 'count':
cubeword.c:48:18: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
48 | else if (a == b && b == c || b == c && c == d || c == d && d == a || d == a && a == b)
| ~~~~~~~^~~~~~~~~
cubeword.c:48:58: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
48 | else if (a == b && b == c || b == c && c == d || c == d && d == a || d == a && a == b)
| ~~~~~~~^~~~~~~~~
cubeword.c:48:78: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
48 | else if (a == b && b == c || b == c && c == d || c == d && d == a || d == a && a == b)
| ~~~~~~~^~~~~~~~~
cubeword.c:50:18: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
50 | else if (a == b && c == d || a == c && b == d || a == d && b == c)
| ~~~~~~~^~~~~~~~~
cubeword.c:50:58: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
50 | else if (a == b && c == d || a == c && b == d || a == d && b == c)
| ~~~~~~~^~~~~~~~~
cubeword.c: In function 'main':
cubeword.c:64:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
cubeword.c:69:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | scanf("%s", s), l = strlen(s);
| ^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
10872 KB |
Output is correct |
2 |
Correct |
171 ms |
10852 KB |
Output is correct |
3 |
Correct |
171 ms |
10752 KB |
Output is correct |
4 |
Correct |
193 ms |
10872 KB |
Output is correct |
5 |
Correct |
181 ms |
10868 KB |
Output is correct |
6 |
Correct |
246 ms |
10832 KB |
Output is correct |
7 |
Correct |
196 ms |
10748 KB |
Output is correct |
8 |
Correct |
188 ms |
10868 KB |
Output is correct |
9 |
Correct |
174 ms |
10868 KB |
Output is correct |
10 |
Correct |
169 ms |
10864 KB |
Output is correct |
11 |
Correct |
173 ms |
10752 KB |
Output is correct |
12 |
Correct |
178 ms |
10864 KB |
Output is correct |
13 |
Correct |
173 ms |
10864 KB |
Output is correct |
14 |
Correct |
205 ms |
10872 KB |
Output is correct |
15 |
Correct |
224 ms |
10908 KB |
Output is correct |
16 |
Correct |
244 ms |
10864 KB |
Output is correct |
17 |
Correct |
245 ms |
10760 KB |
Output is correct |
18 |
Correct |
208 ms |
10752 KB |
Output is correct |
19 |
Correct |
217 ms |
10828 KB |
Output is correct |
20 |
Correct |
203 ms |
10796 KB |
Output is correct |
21 |
Correct |
234 ms |
10860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
10872 KB |
Output is correct |
2 |
Correct |
171 ms |
10852 KB |
Output is correct |
3 |
Correct |
171 ms |
10752 KB |
Output is correct |
4 |
Correct |
193 ms |
10872 KB |
Output is correct |
5 |
Correct |
181 ms |
10868 KB |
Output is correct |
6 |
Correct |
246 ms |
10832 KB |
Output is correct |
7 |
Correct |
196 ms |
10748 KB |
Output is correct |
8 |
Correct |
188 ms |
10868 KB |
Output is correct |
9 |
Correct |
174 ms |
10868 KB |
Output is correct |
10 |
Correct |
169 ms |
10864 KB |
Output is correct |
11 |
Correct |
173 ms |
10752 KB |
Output is correct |
12 |
Correct |
178 ms |
10864 KB |
Output is correct |
13 |
Correct |
173 ms |
10864 KB |
Output is correct |
14 |
Correct |
205 ms |
10872 KB |
Output is correct |
15 |
Correct |
224 ms |
10908 KB |
Output is correct |
16 |
Correct |
244 ms |
10864 KB |
Output is correct |
17 |
Correct |
245 ms |
10760 KB |
Output is correct |
18 |
Correct |
208 ms |
10752 KB |
Output is correct |
19 |
Correct |
217 ms |
10828 KB |
Output is correct |
20 |
Correct |
203 ms |
10796 KB |
Output is correct |
21 |
Correct |
234 ms |
10860 KB |
Output is correct |
22 |
Correct |
230 ms |
10796 KB |
Output is correct |
23 |
Correct |
220 ms |
10792 KB |
Output is correct |
24 |
Correct |
219 ms |
10708 KB |
Output is correct |
25 |
Correct |
204 ms |
10796 KB |
Output is correct |
26 |
Correct |
219 ms |
10796 KB |
Output is correct |
27 |
Correct |
238 ms |
10796 KB |
Output is correct |
28 |
Correct |
234 ms |
10792 KB |
Output is correct |
29 |
Correct |
210 ms |
10792 KB |
Output is correct |
30 |
Correct |
255 ms |
10788 KB |
Output is correct |
31 |
Correct |
201 ms |
10724 KB |
Output is correct |
32 |
Correct |
213 ms |
10800 KB |
Output is correct |
33 |
Correct |
224 ms |
10792 KB |
Output is correct |
34 |
Correct |
212 ms |
10800 KB |
Output is correct |
35 |
Correct |
229 ms |
10800 KB |
Output is correct |
36 |
Correct |
200 ms |
10748 KB |
Output is correct |
37 |
Correct |
215 ms |
10836 KB |
Output is correct |
38 |
Correct |
194 ms |
10788 KB |
Output is correct |
39 |
Correct |
194 ms |
10788 KB |
Output is correct |
40 |
Correct |
233 ms |
10788 KB |
Output is correct |
41 |
Correct |
237 ms |
10732 KB |
Output is correct |
42 |
Correct |
198 ms |
10784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
10872 KB |
Output is correct |
2 |
Correct |
171 ms |
10852 KB |
Output is correct |
3 |
Correct |
171 ms |
10752 KB |
Output is correct |
4 |
Correct |
193 ms |
10872 KB |
Output is correct |
5 |
Correct |
181 ms |
10868 KB |
Output is correct |
6 |
Correct |
246 ms |
10832 KB |
Output is correct |
7 |
Correct |
196 ms |
10748 KB |
Output is correct |
8 |
Correct |
188 ms |
10868 KB |
Output is correct |
9 |
Correct |
174 ms |
10868 KB |
Output is correct |
10 |
Correct |
169 ms |
10864 KB |
Output is correct |
11 |
Correct |
173 ms |
10752 KB |
Output is correct |
12 |
Correct |
178 ms |
10864 KB |
Output is correct |
13 |
Correct |
173 ms |
10864 KB |
Output is correct |
14 |
Correct |
205 ms |
10872 KB |
Output is correct |
15 |
Correct |
224 ms |
10908 KB |
Output is correct |
16 |
Correct |
244 ms |
10864 KB |
Output is correct |
17 |
Correct |
245 ms |
10760 KB |
Output is correct |
18 |
Correct |
208 ms |
10752 KB |
Output is correct |
19 |
Correct |
217 ms |
10828 KB |
Output is correct |
20 |
Correct |
203 ms |
10796 KB |
Output is correct |
21 |
Correct |
234 ms |
10860 KB |
Output is correct |
22 |
Correct |
230 ms |
10796 KB |
Output is correct |
23 |
Correct |
220 ms |
10792 KB |
Output is correct |
24 |
Correct |
219 ms |
10708 KB |
Output is correct |
25 |
Correct |
204 ms |
10796 KB |
Output is correct |
26 |
Correct |
219 ms |
10796 KB |
Output is correct |
27 |
Correct |
238 ms |
10796 KB |
Output is correct |
28 |
Correct |
234 ms |
10792 KB |
Output is correct |
29 |
Correct |
210 ms |
10792 KB |
Output is correct |
30 |
Correct |
255 ms |
10788 KB |
Output is correct |
31 |
Correct |
201 ms |
10724 KB |
Output is correct |
32 |
Correct |
213 ms |
10800 KB |
Output is correct |
33 |
Correct |
224 ms |
10792 KB |
Output is correct |
34 |
Correct |
212 ms |
10800 KB |
Output is correct |
35 |
Correct |
229 ms |
10800 KB |
Output is correct |
36 |
Correct |
200 ms |
10748 KB |
Output is correct |
37 |
Correct |
215 ms |
10836 KB |
Output is correct |
38 |
Correct |
194 ms |
10788 KB |
Output is correct |
39 |
Correct |
194 ms |
10788 KB |
Output is correct |
40 |
Correct |
233 ms |
10788 KB |
Output is correct |
41 |
Correct |
237 ms |
10732 KB |
Output is correct |
42 |
Correct |
198 ms |
10784 KB |
Output is correct |
43 |
Correct |
246 ms |
10760 KB |
Output is correct |
44 |
Correct |
209 ms |
10800 KB |
Output is correct |
45 |
Correct |
233 ms |
10816 KB |
Output is correct |
46 |
Correct |
212 ms |
10824 KB |
Output is correct |
47 |
Correct |
195 ms |
10808 KB |
Output is correct |
48 |
Correct |
242 ms |
10820 KB |
Output is correct |
49 |
Correct |
234 ms |
10828 KB |
Output is correct |
50 |
Correct |
194 ms |
10768 KB |
Output is correct |
51 |
Correct |
190 ms |
10812 KB |
Output is correct |
52 |
Correct |
218 ms |
10816 KB |
Output is correct |
53 |
Correct |
193 ms |
10816 KB |
Output is correct |
54 |
Correct |
211 ms |
10812 KB |
Output is correct |
55 |
Correct |
231 ms |
10816 KB |
Output is correct |
56 |
Correct |
225 ms |
10812 KB |
Output is correct |
57 |
Correct |
212 ms |
10808 KB |
Output is correct |
58 |
Correct |
191 ms |
10712 KB |
Output is correct |
59 |
Correct |
215 ms |
10756 KB |
Output is correct |
60 |
Correct |
208 ms |
10716 KB |
Output is correct |
61 |
Correct |
192 ms |
10748 KB |
Output is correct |
62 |
Correct |
191 ms |
10756 KB |
Output is correct |
63 |
Correct |
189 ms |
10756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
10872 KB |
Output is correct |
2 |
Correct |
171 ms |
10852 KB |
Output is correct |
3 |
Correct |
171 ms |
10752 KB |
Output is correct |
4 |
Correct |
193 ms |
10872 KB |
Output is correct |
5 |
Correct |
181 ms |
10868 KB |
Output is correct |
6 |
Correct |
246 ms |
10832 KB |
Output is correct |
7 |
Correct |
196 ms |
10748 KB |
Output is correct |
8 |
Correct |
188 ms |
10868 KB |
Output is correct |
9 |
Correct |
174 ms |
10868 KB |
Output is correct |
10 |
Correct |
169 ms |
10864 KB |
Output is correct |
11 |
Correct |
173 ms |
10752 KB |
Output is correct |
12 |
Correct |
178 ms |
10864 KB |
Output is correct |
13 |
Correct |
173 ms |
10864 KB |
Output is correct |
14 |
Correct |
205 ms |
10872 KB |
Output is correct |
15 |
Correct |
224 ms |
10908 KB |
Output is correct |
16 |
Correct |
244 ms |
10864 KB |
Output is correct |
17 |
Correct |
245 ms |
10760 KB |
Output is correct |
18 |
Correct |
208 ms |
10752 KB |
Output is correct |
19 |
Correct |
217 ms |
10828 KB |
Output is correct |
20 |
Correct |
203 ms |
10796 KB |
Output is correct |
21 |
Correct |
234 ms |
10860 KB |
Output is correct |
22 |
Correct |
230 ms |
10796 KB |
Output is correct |
23 |
Correct |
220 ms |
10792 KB |
Output is correct |
24 |
Correct |
219 ms |
10708 KB |
Output is correct |
25 |
Correct |
204 ms |
10796 KB |
Output is correct |
26 |
Correct |
219 ms |
10796 KB |
Output is correct |
27 |
Correct |
238 ms |
10796 KB |
Output is correct |
28 |
Correct |
234 ms |
10792 KB |
Output is correct |
29 |
Correct |
210 ms |
10792 KB |
Output is correct |
30 |
Correct |
255 ms |
10788 KB |
Output is correct |
31 |
Correct |
201 ms |
10724 KB |
Output is correct |
32 |
Correct |
213 ms |
10800 KB |
Output is correct |
33 |
Correct |
224 ms |
10792 KB |
Output is correct |
34 |
Correct |
212 ms |
10800 KB |
Output is correct |
35 |
Correct |
229 ms |
10800 KB |
Output is correct |
36 |
Correct |
200 ms |
10748 KB |
Output is correct |
37 |
Correct |
215 ms |
10836 KB |
Output is correct |
38 |
Correct |
194 ms |
10788 KB |
Output is correct |
39 |
Correct |
194 ms |
10788 KB |
Output is correct |
40 |
Correct |
233 ms |
10788 KB |
Output is correct |
41 |
Correct |
237 ms |
10732 KB |
Output is correct |
42 |
Correct |
198 ms |
10784 KB |
Output is correct |
43 |
Correct |
246 ms |
10760 KB |
Output is correct |
44 |
Correct |
209 ms |
10800 KB |
Output is correct |
45 |
Correct |
233 ms |
10816 KB |
Output is correct |
46 |
Correct |
212 ms |
10824 KB |
Output is correct |
47 |
Correct |
195 ms |
10808 KB |
Output is correct |
48 |
Correct |
242 ms |
10820 KB |
Output is correct |
49 |
Correct |
234 ms |
10828 KB |
Output is correct |
50 |
Correct |
194 ms |
10768 KB |
Output is correct |
51 |
Correct |
190 ms |
10812 KB |
Output is correct |
52 |
Correct |
218 ms |
10816 KB |
Output is correct |
53 |
Correct |
193 ms |
10816 KB |
Output is correct |
54 |
Correct |
211 ms |
10812 KB |
Output is correct |
55 |
Correct |
231 ms |
10816 KB |
Output is correct |
56 |
Correct |
225 ms |
10812 KB |
Output is correct |
57 |
Correct |
212 ms |
10808 KB |
Output is correct |
58 |
Correct |
191 ms |
10712 KB |
Output is correct |
59 |
Correct |
215 ms |
10756 KB |
Output is correct |
60 |
Correct |
208 ms |
10716 KB |
Output is correct |
61 |
Correct |
192 ms |
10748 KB |
Output is correct |
62 |
Correct |
191 ms |
10756 KB |
Output is correct |
63 |
Correct |
189 ms |
10756 KB |
Output is correct |
64 |
Correct |
212 ms |
10816 KB |
Output is correct |
65 |
Correct |
216 ms |
10812 KB |
Output is correct |
66 |
Correct |
240 ms |
10812 KB |
Output is correct |
67 |
Correct |
201 ms |
10820 KB |
Output is correct |
68 |
Correct |
207 ms |
10752 KB |
Output is correct |
69 |
Correct |
193 ms |
10756 KB |
Output is correct |
70 |
Correct |
190 ms |
10808 KB |
Output is correct |
71 |
Correct |
214 ms |
10928 KB |
Output is correct |
72 |
Correct |
234 ms |
10776 KB |
Output is correct |
73 |
Correct |
194 ms |
10812 KB |
Output is correct |
74 |
Correct |
209 ms |
10752 KB |
Output is correct |
75 |
Correct |
218 ms |
10820 KB |
Output is correct |
76 |
Correct |
194 ms |
10816 KB |
Output is correct |
77 |
Correct |
213 ms |
10812 KB |
Output is correct |
78 |
Correct |
224 ms |
10812 KB |
Output is correct |
79 |
Correct |
211 ms |
10808 KB |
Output is correct |
80 |
Correct |
197 ms |
10752 KB |
Output is correct |
81 |
Correct |
245 ms |
10808 KB |
Output is correct |
82 |
Correct |
206 ms |
10816 KB |
Output is correct |
83 |
Correct |
214 ms |
10812 KB |
Output is correct |
84 |
Correct |
196 ms |
10748 KB |
Output is correct |