#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int mod = 998244353, abc = 32;
//const int mod = 998244353, abc = 26;
void upd(int &a, const int &b) { a = (a + b) % mod; }
int mul(const int &a, const int &b) { return (a * 1ll * b) % (ll)mod; }
int conv(char c)
{
if ('a' <= c && c <= 'z') return c - 'a';
if ('A' <= c && c <= 'Z') return 16 + c - 'A';
//if ('0' <= c && c <= '9') return 26 + 26 + c - '0';
}
int cnt[abc][abc][abc], e[abc][abc], ans = 0;
void solve(const set<string> &v)
{
memset(cnt, 0, sizeof(cnt)), memset(e, 0, sizeof(e));
for (const string &i : v) e[conv(i[0])][conv(i.back())]++;
for (int c1 = 0; c1 < abc; c1++) for (int c2 = 0; c2 < abc; c2++) for (int c3 = 0; c3 < abc; c3++)
for (int ja = 0; ja < abc; ja++)
upd(cnt[c1][c2][c3], mul(mul(e[ja][c1], e[ja][c2]), e[ja][c3]));
for (int c1 = 0; c1 < abc; c1++) for (int c2 = 0; c2 < abc; c2++)
for (int c3 = 0; c3 < abc; c3++) for (int c4 = 0; c4 < abc; c4++)
upd(ans, mul(mul(cnt[c1][c2][c3], cnt[c2][c3][c4]), mul(cnt[c3][c4][c1], cnt[c4][c1][c2])));
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<set<string> > v(11);
for (int i = 0; i < n; i++)
{
string s;
cin >> s;
v[s.size()].insert(s);
reverse(s.begin(), s.end());
v[s.size()].insert(s);
}
for (int i = 3; i <= 10; i++) if (v[i].size()) solve(v[i]);
cout << ans << "\n";
return 0;
}
Compilation message
cubeword.cpp: In function 'int conv(char)':
cubeword.cpp:14:1: warning: control reaches end of non-void function [-Wreturn-type]
14 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
300 ms |
14828 KB |
Output is correct |
2 |
Correct |
328 ms |
15712 KB |
Output is correct |
3 |
Correct |
301 ms |
15776 KB |
Output is correct |
4 |
Correct |
284 ms |
15760 KB |
Output is correct |
5 |
Correct |
328 ms |
15772 KB |
Output is correct |
6 |
Correct |
334 ms |
15772 KB |
Output is correct |
7 |
Correct |
335 ms |
15780 KB |
Output is correct |
8 |
Correct |
292 ms |
15776 KB |
Output is correct |
9 |
Correct |
298 ms |
15768 KB |
Output is correct |
10 |
Correct |
310 ms |
15700 KB |
Output is correct |
11 |
Correct |
302 ms |
15684 KB |
Output is correct |
12 |
Correct |
307 ms |
15828 KB |
Output is correct |
13 |
Correct |
343 ms |
15752 KB |
Output is correct |
14 |
Correct |
299 ms |
15780 KB |
Output is correct |
15 |
Correct |
299 ms |
15788 KB |
Output is correct |
16 |
Correct |
331 ms |
15760 KB |
Output is correct |
17 |
Correct |
309 ms |
15776 KB |
Output is correct |
18 |
Correct |
321 ms |
15764 KB |
Output is correct |
19 |
Correct |
320 ms |
15764 KB |
Output is correct |
20 |
Correct |
307 ms |
15668 KB |
Output is correct |
21 |
Correct |
313 ms |
15760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
300 ms |
14828 KB |
Output is correct |
2 |
Correct |
328 ms |
15712 KB |
Output is correct |
3 |
Correct |
301 ms |
15776 KB |
Output is correct |
4 |
Correct |
284 ms |
15760 KB |
Output is correct |
5 |
Correct |
328 ms |
15772 KB |
Output is correct |
6 |
Correct |
334 ms |
15772 KB |
Output is correct |
7 |
Correct |
335 ms |
15780 KB |
Output is correct |
8 |
Correct |
292 ms |
15776 KB |
Output is correct |
9 |
Correct |
298 ms |
15768 KB |
Output is correct |
10 |
Correct |
310 ms |
15700 KB |
Output is correct |
11 |
Correct |
302 ms |
15684 KB |
Output is correct |
12 |
Correct |
307 ms |
15828 KB |
Output is correct |
13 |
Correct |
343 ms |
15752 KB |
Output is correct |
14 |
Correct |
299 ms |
15780 KB |
Output is correct |
15 |
Correct |
299 ms |
15788 KB |
Output is correct |
16 |
Correct |
331 ms |
15760 KB |
Output is correct |
17 |
Correct |
309 ms |
15776 KB |
Output is correct |
18 |
Correct |
321 ms |
15764 KB |
Output is correct |
19 |
Correct |
320 ms |
15764 KB |
Output is correct |
20 |
Correct |
307 ms |
15668 KB |
Output is correct |
21 |
Correct |
313 ms |
15760 KB |
Output is correct |
22 |
Correct |
299 ms |
16408 KB |
Output is correct |
23 |
Correct |
285 ms |
16360 KB |
Output is correct |
24 |
Correct |
304 ms |
16404 KB |
Output is correct |
25 |
Correct |
334 ms |
16432 KB |
Output is correct |
26 |
Correct |
286 ms |
16324 KB |
Output is correct |
27 |
Correct |
307 ms |
16316 KB |
Output is correct |
28 |
Correct |
293 ms |
16344 KB |
Output is correct |
29 |
Correct |
297 ms |
16444 KB |
Output is correct |
30 |
Correct |
320 ms |
16308 KB |
Output is correct |
31 |
Correct |
319 ms |
16360 KB |
Output is correct |
32 |
Correct |
287 ms |
16436 KB |
Output is correct |
33 |
Correct |
326 ms |
16332 KB |
Output is correct |
34 |
Correct |
321 ms |
16348 KB |
Output is correct |
35 |
Correct |
315 ms |
16272 KB |
Output is correct |
36 |
Correct |
294 ms |
16396 KB |
Output is correct |
37 |
Correct |
306 ms |
16340 KB |
Output is correct |
38 |
Correct |
292 ms |
16452 KB |
Output is correct |
39 |
Correct |
278 ms |
16340 KB |
Output is correct |
40 |
Correct |
283 ms |
16452 KB |
Output is correct |
41 |
Correct |
334 ms |
16344 KB |
Output is correct |
42 |
Correct |
306 ms |
16304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
300 ms |
14828 KB |
Output is correct |
2 |
Correct |
328 ms |
15712 KB |
Output is correct |
3 |
Correct |
301 ms |
15776 KB |
Output is correct |
4 |
Correct |
284 ms |
15760 KB |
Output is correct |
5 |
Correct |
328 ms |
15772 KB |
Output is correct |
6 |
Correct |
334 ms |
15772 KB |
Output is correct |
7 |
Correct |
335 ms |
15780 KB |
Output is correct |
8 |
Correct |
292 ms |
15776 KB |
Output is correct |
9 |
Correct |
298 ms |
15768 KB |
Output is correct |
10 |
Correct |
310 ms |
15700 KB |
Output is correct |
11 |
Correct |
302 ms |
15684 KB |
Output is correct |
12 |
Correct |
307 ms |
15828 KB |
Output is correct |
13 |
Correct |
343 ms |
15752 KB |
Output is correct |
14 |
Correct |
299 ms |
15780 KB |
Output is correct |
15 |
Correct |
299 ms |
15788 KB |
Output is correct |
16 |
Correct |
331 ms |
15760 KB |
Output is correct |
17 |
Correct |
309 ms |
15776 KB |
Output is correct |
18 |
Correct |
321 ms |
15764 KB |
Output is correct |
19 |
Correct |
320 ms |
15764 KB |
Output is correct |
20 |
Correct |
307 ms |
15668 KB |
Output is correct |
21 |
Correct |
313 ms |
15760 KB |
Output is correct |
22 |
Correct |
299 ms |
16408 KB |
Output is correct |
23 |
Correct |
285 ms |
16360 KB |
Output is correct |
24 |
Correct |
304 ms |
16404 KB |
Output is correct |
25 |
Correct |
334 ms |
16432 KB |
Output is correct |
26 |
Correct |
286 ms |
16324 KB |
Output is correct |
27 |
Correct |
307 ms |
16316 KB |
Output is correct |
28 |
Correct |
293 ms |
16344 KB |
Output is correct |
29 |
Correct |
297 ms |
16444 KB |
Output is correct |
30 |
Correct |
320 ms |
16308 KB |
Output is correct |
31 |
Correct |
319 ms |
16360 KB |
Output is correct |
32 |
Correct |
287 ms |
16436 KB |
Output is correct |
33 |
Correct |
326 ms |
16332 KB |
Output is correct |
34 |
Correct |
321 ms |
16348 KB |
Output is correct |
35 |
Correct |
315 ms |
16272 KB |
Output is correct |
36 |
Correct |
294 ms |
16396 KB |
Output is correct |
37 |
Correct |
306 ms |
16340 KB |
Output is correct |
38 |
Correct |
292 ms |
16452 KB |
Output is correct |
39 |
Correct |
278 ms |
16340 KB |
Output is correct |
40 |
Correct |
283 ms |
16452 KB |
Output is correct |
41 |
Correct |
334 ms |
16344 KB |
Output is correct |
42 |
Correct |
306 ms |
16304 KB |
Output is correct |
43 |
Correct |
343 ms |
16548 KB |
Output is correct |
44 |
Correct |
300 ms |
16540 KB |
Output is correct |
45 |
Correct |
353 ms |
16524 KB |
Output is correct |
46 |
Correct |
330 ms |
16524 KB |
Output is correct |
47 |
Correct |
316 ms |
16564 KB |
Output is correct |
48 |
Correct |
320 ms |
16528 KB |
Output is correct |
49 |
Correct |
353 ms |
16532 KB |
Output is correct |
50 |
Correct |
293 ms |
16532 KB |
Output is correct |
51 |
Correct |
319 ms |
16464 KB |
Output is correct |
52 |
Correct |
325 ms |
16516 KB |
Output is correct |
53 |
Correct |
314 ms |
16528 KB |
Output is correct |
54 |
Correct |
330 ms |
16448 KB |
Output is correct |
55 |
Correct |
319 ms |
16556 KB |
Output is correct |
56 |
Correct |
291 ms |
16732 KB |
Output is correct |
57 |
Correct |
311 ms |
16504 KB |
Output is correct |
58 |
Correct |
287 ms |
16444 KB |
Output is correct |
59 |
Correct |
300 ms |
16528 KB |
Output is correct |
60 |
Correct |
314 ms |
16452 KB |
Output is correct |
61 |
Correct |
285 ms |
16452 KB |
Output is correct |
62 |
Correct |
315 ms |
16516 KB |
Output is correct |
63 |
Correct |
297 ms |
16520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
300 ms |
14828 KB |
Output is correct |
2 |
Correct |
328 ms |
15712 KB |
Output is correct |
3 |
Correct |
301 ms |
15776 KB |
Output is correct |
4 |
Correct |
284 ms |
15760 KB |
Output is correct |
5 |
Correct |
328 ms |
15772 KB |
Output is correct |
6 |
Correct |
334 ms |
15772 KB |
Output is correct |
7 |
Correct |
335 ms |
15780 KB |
Output is correct |
8 |
Correct |
292 ms |
15776 KB |
Output is correct |
9 |
Correct |
298 ms |
15768 KB |
Output is correct |
10 |
Correct |
310 ms |
15700 KB |
Output is correct |
11 |
Correct |
302 ms |
15684 KB |
Output is correct |
12 |
Correct |
307 ms |
15828 KB |
Output is correct |
13 |
Correct |
343 ms |
15752 KB |
Output is correct |
14 |
Correct |
299 ms |
15780 KB |
Output is correct |
15 |
Correct |
299 ms |
15788 KB |
Output is correct |
16 |
Correct |
331 ms |
15760 KB |
Output is correct |
17 |
Correct |
309 ms |
15776 KB |
Output is correct |
18 |
Correct |
321 ms |
15764 KB |
Output is correct |
19 |
Correct |
320 ms |
15764 KB |
Output is correct |
20 |
Correct |
307 ms |
15668 KB |
Output is correct |
21 |
Correct |
313 ms |
15760 KB |
Output is correct |
22 |
Correct |
299 ms |
16408 KB |
Output is correct |
23 |
Correct |
285 ms |
16360 KB |
Output is correct |
24 |
Correct |
304 ms |
16404 KB |
Output is correct |
25 |
Correct |
334 ms |
16432 KB |
Output is correct |
26 |
Correct |
286 ms |
16324 KB |
Output is correct |
27 |
Correct |
307 ms |
16316 KB |
Output is correct |
28 |
Correct |
293 ms |
16344 KB |
Output is correct |
29 |
Correct |
297 ms |
16444 KB |
Output is correct |
30 |
Correct |
320 ms |
16308 KB |
Output is correct |
31 |
Correct |
319 ms |
16360 KB |
Output is correct |
32 |
Correct |
287 ms |
16436 KB |
Output is correct |
33 |
Correct |
326 ms |
16332 KB |
Output is correct |
34 |
Correct |
321 ms |
16348 KB |
Output is correct |
35 |
Correct |
315 ms |
16272 KB |
Output is correct |
36 |
Correct |
294 ms |
16396 KB |
Output is correct |
37 |
Correct |
306 ms |
16340 KB |
Output is correct |
38 |
Correct |
292 ms |
16452 KB |
Output is correct |
39 |
Correct |
278 ms |
16340 KB |
Output is correct |
40 |
Correct |
283 ms |
16452 KB |
Output is correct |
41 |
Correct |
334 ms |
16344 KB |
Output is correct |
42 |
Correct |
306 ms |
16304 KB |
Output is correct |
43 |
Correct |
343 ms |
16548 KB |
Output is correct |
44 |
Correct |
300 ms |
16540 KB |
Output is correct |
45 |
Correct |
353 ms |
16524 KB |
Output is correct |
46 |
Correct |
330 ms |
16524 KB |
Output is correct |
47 |
Correct |
316 ms |
16564 KB |
Output is correct |
48 |
Correct |
320 ms |
16528 KB |
Output is correct |
49 |
Correct |
353 ms |
16532 KB |
Output is correct |
50 |
Correct |
293 ms |
16532 KB |
Output is correct |
51 |
Correct |
319 ms |
16464 KB |
Output is correct |
52 |
Correct |
325 ms |
16516 KB |
Output is correct |
53 |
Correct |
314 ms |
16528 KB |
Output is correct |
54 |
Correct |
330 ms |
16448 KB |
Output is correct |
55 |
Correct |
319 ms |
16556 KB |
Output is correct |
56 |
Correct |
291 ms |
16732 KB |
Output is correct |
57 |
Correct |
311 ms |
16504 KB |
Output is correct |
58 |
Correct |
287 ms |
16444 KB |
Output is correct |
59 |
Correct |
300 ms |
16528 KB |
Output is correct |
60 |
Correct |
314 ms |
16452 KB |
Output is correct |
61 |
Correct |
285 ms |
16452 KB |
Output is correct |
62 |
Correct |
315 ms |
16516 KB |
Output is correct |
63 |
Correct |
297 ms |
16520 KB |
Output is correct |
64 |
Incorrect |
310 ms |
16756 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |