Submission #283456

# Submission time Handle Problem Language Result Execution time Memory
283456 2020-08-25T19:16:44 Z dolphingarlic Cubeword (CEOI19_cubeword) C++14
100 / 100
380 ms 18808 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const ll MOD = 998244353;

inline int id(char c) {
    if (c >= 'a' && c <= 'z') return c - 'a';
    if (c >= 'A' && c <= 'Z') return c - 'A' + 26;
    return c - '0' + 52;
}

set<string> words[11];
ll cnt[62][62], dp[62][62][62], perm[8] = {24, 12, 12, 4, 12, 6, 4, 1};

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        words[s.size()].insert(s);
        reverse(s.begin(), s.end());
        words[s.size()].insert(s);
    }

    ll ans = 0;
    for (int l = 3; l < 11; l++) {
        memset(cnt, 0, sizeof cnt);
        memset(dp, 0, sizeof dp);
        for (string i : words[l]) cnt[id(i[0])][id(i.back())]++;
        for (int i = 0; i < 62; i++) {
            for (int a = 0; a < 62; a++) {
                for (int b = a; b < 62; b++) {
                    for (int c = b; c < 62; c++) {
                        dp[a][b][c] = (dp[a][b][c] + cnt[i][a] * cnt[i][b] % MOD * cnt[i][c] % MOD) % MOD;
                    }
                }
            }
        }
        for (int a = 0; a < 62; a++) {
            for (int b = a; b < 62; b++) {
                for (int c = b; c < 62; c++) {
                    for (int d = c; d < 62; d++) {
                        int mask = (a == b) << 2 | (b == c) << 1 | (c == d);
                        ans = (ans + dp[a][b][c] * dp[a][b][d] % MOD * dp[a][c][d] % MOD * dp[b][c][d] % MOD * perm[mask] % MOD) % MOD;
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 327 ms 17528 KB Output is correct
2 Correct 331 ms 17656 KB Output is correct
3 Correct 328 ms 17528 KB Output is correct
4 Correct 330 ms 17656 KB Output is correct
5 Correct 331 ms 17656 KB Output is correct
6 Correct 323 ms 17660 KB Output is correct
7 Correct 333 ms 17528 KB Output is correct
8 Correct 347 ms 17528 KB Output is correct
9 Correct 341 ms 17532 KB Output is correct
10 Correct 333 ms 17532 KB Output is correct
11 Correct 341 ms 17528 KB Output is correct
12 Correct 350 ms 17660 KB Output is correct
13 Correct 348 ms 17656 KB Output is correct
14 Correct 353 ms 17528 KB Output is correct
15 Correct 333 ms 17656 KB Output is correct
16 Correct 332 ms 17528 KB Output is correct
17 Correct 332 ms 17764 KB Output is correct
18 Correct 329 ms 17528 KB Output is correct
19 Correct 328 ms 17668 KB Output is correct
20 Correct 327 ms 17528 KB Output is correct
21 Correct 326 ms 17656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 327 ms 17528 KB Output is correct
2 Correct 331 ms 17656 KB Output is correct
3 Correct 328 ms 17528 KB Output is correct
4 Correct 330 ms 17656 KB Output is correct
5 Correct 331 ms 17656 KB Output is correct
6 Correct 323 ms 17660 KB Output is correct
7 Correct 333 ms 17528 KB Output is correct
8 Correct 347 ms 17528 KB Output is correct
9 Correct 341 ms 17532 KB Output is correct
10 Correct 333 ms 17532 KB Output is correct
11 Correct 341 ms 17528 KB Output is correct
12 Correct 350 ms 17660 KB Output is correct
13 Correct 348 ms 17656 KB Output is correct
14 Correct 353 ms 17528 KB Output is correct
15 Correct 333 ms 17656 KB Output is correct
16 Correct 332 ms 17528 KB Output is correct
17 Correct 332 ms 17764 KB Output is correct
18 Correct 329 ms 17528 KB Output is correct
19 Correct 328 ms 17668 KB Output is correct
20 Correct 327 ms 17528 KB Output is correct
21 Correct 326 ms 17656 KB Output is correct
22 Correct 326 ms 18168 KB Output is correct
23 Correct 342 ms 18196 KB Output is correct
24 Correct 344 ms 18200 KB Output is correct
25 Correct 337 ms 18296 KB Output is correct
26 Correct 332 ms 18188 KB Output is correct
27 Correct 317 ms 18168 KB Output is correct
28 Correct 330 ms 18216 KB Output is correct
29 Correct 331 ms 18168 KB Output is correct
30 Correct 340 ms 18184 KB Output is correct
31 Correct 332 ms 18168 KB Output is correct
32 Correct 350 ms 18364 KB Output is correct
33 Correct 326 ms 18172 KB Output is correct
34 Correct 350 ms 18124 KB Output is correct
35 Correct 338 ms 18168 KB Output is correct
36 Correct 332 ms 18296 KB Output is correct
37 Correct 324 ms 18172 KB Output is correct
38 Correct 332 ms 18168 KB Output is correct
39 Correct 349 ms 18296 KB Output is correct
40 Correct 339 ms 18168 KB Output is correct
41 Correct 336 ms 18168 KB Output is correct
42 Correct 380 ms 18168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 327 ms 17528 KB Output is correct
2 Correct 331 ms 17656 KB Output is correct
3 Correct 328 ms 17528 KB Output is correct
4 Correct 330 ms 17656 KB Output is correct
5 Correct 331 ms 17656 KB Output is correct
6 Correct 323 ms 17660 KB Output is correct
7 Correct 333 ms 17528 KB Output is correct
8 Correct 347 ms 17528 KB Output is correct
9 Correct 341 ms 17532 KB Output is correct
10 Correct 333 ms 17532 KB Output is correct
11 Correct 341 ms 17528 KB Output is correct
12 Correct 350 ms 17660 KB Output is correct
13 Correct 348 ms 17656 KB Output is correct
14 Correct 353 ms 17528 KB Output is correct
15 Correct 333 ms 17656 KB Output is correct
16 Correct 332 ms 17528 KB Output is correct
17 Correct 332 ms 17764 KB Output is correct
18 Correct 329 ms 17528 KB Output is correct
19 Correct 328 ms 17668 KB Output is correct
20 Correct 327 ms 17528 KB Output is correct
21 Correct 326 ms 17656 KB Output is correct
22 Correct 326 ms 18168 KB Output is correct
23 Correct 342 ms 18196 KB Output is correct
24 Correct 344 ms 18200 KB Output is correct
25 Correct 337 ms 18296 KB Output is correct
26 Correct 332 ms 18188 KB Output is correct
27 Correct 317 ms 18168 KB Output is correct
28 Correct 330 ms 18216 KB Output is correct
29 Correct 331 ms 18168 KB Output is correct
30 Correct 340 ms 18184 KB Output is correct
31 Correct 332 ms 18168 KB Output is correct
32 Correct 350 ms 18364 KB Output is correct
33 Correct 326 ms 18172 KB Output is correct
34 Correct 350 ms 18124 KB Output is correct
35 Correct 338 ms 18168 KB Output is correct
36 Correct 332 ms 18296 KB Output is correct
37 Correct 324 ms 18172 KB Output is correct
38 Correct 332 ms 18168 KB Output is correct
39 Correct 349 ms 18296 KB Output is correct
40 Correct 339 ms 18168 KB Output is correct
41 Correct 336 ms 18168 KB Output is correct
42 Correct 380 ms 18168 KB Output is correct
43 Correct 341 ms 18296 KB Output is correct
44 Correct 353 ms 18424 KB Output is correct
45 Correct 345 ms 18296 KB Output is correct
46 Correct 338 ms 18424 KB Output is correct
47 Correct 348 ms 18296 KB Output is correct
48 Correct 344 ms 18424 KB Output is correct
49 Correct 349 ms 18424 KB Output is correct
50 Correct 348 ms 18296 KB Output is correct
51 Correct 350 ms 18296 KB Output is correct
52 Correct 349 ms 18296 KB Output is correct
53 Correct 354 ms 18296 KB Output is correct
54 Correct 331 ms 18316 KB Output is correct
55 Correct 332 ms 18296 KB Output is correct
56 Correct 346 ms 18384 KB Output is correct
57 Correct 348 ms 18296 KB Output is correct
58 Correct 343 ms 18272 KB Output is correct
59 Correct 366 ms 18424 KB Output is correct
60 Correct 329 ms 18296 KB Output is correct
61 Correct 330 ms 18424 KB Output is correct
62 Correct 326 ms 18484 KB Output is correct
63 Correct 333 ms 18296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 327 ms 17528 KB Output is correct
2 Correct 331 ms 17656 KB Output is correct
3 Correct 328 ms 17528 KB Output is correct
4 Correct 330 ms 17656 KB Output is correct
5 Correct 331 ms 17656 KB Output is correct
6 Correct 323 ms 17660 KB Output is correct
7 Correct 333 ms 17528 KB Output is correct
8 Correct 347 ms 17528 KB Output is correct
9 Correct 341 ms 17532 KB Output is correct
10 Correct 333 ms 17532 KB Output is correct
11 Correct 341 ms 17528 KB Output is correct
12 Correct 350 ms 17660 KB Output is correct
13 Correct 348 ms 17656 KB Output is correct
14 Correct 353 ms 17528 KB Output is correct
15 Correct 333 ms 17656 KB Output is correct
16 Correct 332 ms 17528 KB Output is correct
17 Correct 332 ms 17764 KB Output is correct
18 Correct 329 ms 17528 KB Output is correct
19 Correct 328 ms 17668 KB Output is correct
20 Correct 327 ms 17528 KB Output is correct
21 Correct 326 ms 17656 KB Output is correct
22 Correct 326 ms 18168 KB Output is correct
23 Correct 342 ms 18196 KB Output is correct
24 Correct 344 ms 18200 KB Output is correct
25 Correct 337 ms 18296 KB Output is correct
26 Correct 332 ms 18188 KB Output is correct
27 Correct 317 ms 18168 KB Output is correct
28 Correct 330 ms 18216 KB Output is correct
29 Correct 331 ms 18168 KB Output is correct
30 Correct 340 ms 18184 KB Output is correct
31 Correct 332 ms 18168 KB Output is correct
32 Correct 350 ms 18364 KB Output is correct
33 Correct 326 ms 18172 KB Output is correct
34 Correct 350 ms 18124 KB Output is correct
35 Correct 338 ms 18168 KB Output is correct
36 Correct 332 ms 18296 KB Output is correct
37 Correct 324 ms 18172 KB Output is correct
38 Correct 332 ms 18168 KB Output is correct
39 Correct 349 ms 18296 KB Output is correct
40 Correct 339 ms 18168 KB Output is correct
41 Correct 336 ms 18168 KB Output is correct
42 Correct 380 ms 18168 KB Output is correct
43 Correct 341 ms 18296 KB Output is correct
44 Correct 353 ms 18424 KB Output is correct
45 Correct 345 ms 18296 KB Output is correct
46 Correct 338 ms 18424 KB Output is correct
47 Correct 348 ms 18296 KB Output is correct
48 Correct 344 ms 18424 KB Output is correct
49 Correct 349 ms 18424 KB Output is correct
50 Correct 348 ms 18296 KB Output is correct
51 Correct 350 ms 18296 KB Output is correct
52 Correct 349 ms 18296 KB Output is correct
53 Correct 354 ms 18296 KB Output is correct
54 Correct 331 ms 18316 KB Output is correct
55 Correct 332 ms 18296 KB Output is correct
56 Correct 346 ms 18384 KB Output is correct
57 Correct 348 ms 18296 KB Output is correct
58 Correct 343 ms 18272 KB Output is correct
59 Correct 366 ms 18424 KB Output is correct
60 Correct 329 ms 18296 KB Output is correct
61 Correct 330 ms 18424 KB Output is correct
62 Correct 326 ms 18484 KB Output is correct
63 Correct 333 ms 18296 KB Output is correct
64 Correct 326 ms 18552 KB Output is correct
65 Correct 323 ms 18552 KB Output is correct
66 Correct 325 ms 18552 KB Output is correct
67 Correct 331 ms 18680 KB Output is correct
68 Correct 334 ms 18552 KB Output is correct
69 Correct 329 ms 18724 KB Output is correct
70 Correct 332 ms 18552 KB Output is correct
71 Correct 329 ms 18680 KB Output is correct
72 Correct 338 ms 18552 KB Output is correct
73 Correct 321 ms 18604 KB Output is correct
74 Correct 341 ms 18808 KB Output is correct
75 Correct 348 ms 18552 KB Output is correct
76 Correct 341 ms 18808 KB Output is correct
77 Correct 334 ms 18552 KB Output is correct
78 Correct 342 ms 18684 KB Output is correct
79 Correct 333 ms 18552 KB Output is correct
80 Correct 347 ms 18680 KB Output is correct
81 Correct 331 ms 18552 KB Output is correct
82 Correct 325 ms 18552 KB Output is correct
83 Correct 334 ms 18648 KB Output is correct
84 Correct 328 ms 18552 KB Output is correct