Submission #546623

# Submission time Handle Problem Language Result Execution time Memory
546623 2022-04-07T21:41:35 Z LucaDantas Cubeword (CEOI19_cubeword) C++17
84 / 100
480 ms 38916 KB
#pragma GCC optimize("Ofast") 
#pragma GCC optimize("unroll-loops") 
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") 
#include <bits/stdc++.h>
using namespace std;

constexpr int maxn = 62, mod = 998244353; // subtasks 1-2

int ans;

int edge[11][maxn][maxn];

int value_triad[11][maxn][maxn][maxn];

int id(char c) { if(c >= 'a') return c-'a'; return 16+c-'A'; } // subtaks 1-2

set<string> mark;

void add(int& a, int b) { a += b; if(a >= mod) a -= mod; }

int D[11][maxn][maxn][maxn], perm[maxn][maxn][maxn][maxn];

const int f[] = {1, 1, 2, 6, 24};

int choose(int a, int b) { return f[a] / (f[b]*f[a-b]); }

void pre() {
    int cnt[maxn]{};
    for(int a = 0; a < maxn; a++) for(int b = a; b < maxn; b++) for(int c = b; c < maxn; c++) for(int d = c; d < maxn; d++) {
        ++cnt[a], ++cnt[b], ++cnt[c], ++cnt[d];
        perm[a][b][c][d] = 1;
        int tot = 4;
        for(int i : {a, b, c, d}) {
            perm[a][b][c][d] *= choose(tot, cnt[i]), tot -= cnt[i];
            cnt[i] = 0;
        }
    }
}

int main() {
    pre();

    int n; cin >> n;
    string s;
    for(int i = 0; i < n; i++) {
        cin >> s;
        for(int rep = 0; rep < 2; rep++, reverse(s.begin(), s.end())) if(!mark.count(s)) {
            edge[s.size()][id(s[0])][id(s.back())]++;
            mark.insert(s);
        }
    }


    for(int sz = 3; sz <= 10; sz++)
        for(int a = 0; a < maxn; a++) for(int b = a; b < maxn; b++) for(int c = b; c < maxn; c++)
            for(int x = 0; x < maxn; x++)
                add(D[sz][a][b][c], 1ll * edge[sz][x][a] * edge[sz][x][b] % mod * edge[sz][x][c] % mod);

    for(int sz = 3; sz <= 10; sz++) {
        for(int a = 0; a < maxn; a++) for(int b = a; b < maxn; b++) for(int c = b; c < maxn; c++) for(int d = c; d < maxn; d++) {
            add(ans, 1ll * D[sz][a][b][c] * D[sz][a][b][d] % mod * D[sz][a][c][d] % mod * D[sz][b][c][d] % mod * perm[a][b][c][d] % mod);
        }
    }

    printf("%d\n", ans);
}
# Verdict Execution time Memory Grader output
1 Correct 427 ms 37764 KB Output is correct
2 Correct 343 ms 37744 KB Output is correct
3 Correct 431 ms 37868 KB Output is correct
4 Correct 350 ms 37788 KB Output is correct
5 Correct 411 ms 37736 KB Output is correct
6 Correct 365 ms 37676 KB Output is correct
7 Correct 343 ms 37796 KB Output is correct
8 Correct 381 ms 37756 KB Output is correct
9 Correct 360 ms 37808 KB Output is correct
10 Correct 390 ms 37740 KB Output is correct
11 Correct 340 ms 37756 KB Output is correct
12 Correct 389 ms 37748 KB Output is correct
13 Correct 379 ms 37764 KB Output is correct
14 Correct 374 ms 37764 KB Output is correct
15 Correct 364 ms 37768 KB Output is correct
16 Correct 384 ms 37628 KB Output is correct
17 Correct 373 ms 37836 KB Output is correct
18 Correct 360 ms 37628 KB Output is correct
19 Correct 389 ms 37736 KB Output is correct
20 Correct 346 ms 37740 KB Output is correct
21 Correct 401 ms 37748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 427 ms 37764 KB Output is correct
2 Correct 343 ms 37744 KB Output is correct
3 Correct 431 ms 37868 KB Output is correct
4 Correct 350 ms 37788 KB Output is correct
5 Correct 411 ms 37736 KB Output is correct
6 Correct 365 ms 37676 KB Output is correct
7 Correct 343 ms 37796 KB Output is correct
8 Correct 381 ms 37756 KB Output is correct
9 Correct 360 ms 37808 KB Output is correct
10 Correct 390 ms 37740 KB Output is correct
11 Correct 340 ms 37756 KB Output is correct
12 Correct 389 ms 37748 KB Output is correct
13 Correct 379 ms 37764 KB Output is correct
14 Correct 374 ms 37764 KB Output is correct
15 Correct 364 ms 37768 KB Output is correct
16 Correct 384 ms 37628 KB Output is correct
17 Correct 373 ms 37836 KB Output is correct
18 Correct 360 ms 37628 KB Output is correct
19 Correct 389 ms 37736 KB Output is correct
20 Correct 346 ms 37740 KB Output is correct
21 Correct 401 ms 37748 KB Output is correct
22 Correct 346 ms 38512 KB Output is correct
23 Correct 366 ms 38436 KB Output is correct
24 Correct 391 ms 38440 KB Output is correct
25 Correct 375 ms 38348 KB Output is correct
26 Correct 368 ms 38404 KB Output is correct
27 Correct 354 ms 38392 KB Output is correct
28 Correct 364 ms 38444 KB Output is correct
29 Correct 395 ms 38512 KB Output is correct
30 Correct 391 ms 38424 KB Output is correct
31 Correct 381 ms 38364 KB Output is correct
32 Correct 364 ms 38396 KB Output is correct
33 Correct 378 ms 38424 KB Output is correct
34 Correct 383 ms 38320 KB Output is correct
35 Correct 480 ms 38440 KB Output is correct
36 Correct 381 ms 38568 KB Output is correct
37 Correct 393 ms 38316 KB Output is correct
38 Correct 383 ms 38376 KB Output is correct
39 Correct 389 ms 38444 KB Output is correct
40 Correct 429 ms 38432 KB Output is correct
41 Correct 408 ms 38436 KB Output is correct
42 Correct 410 ms 38432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 427 ms 37764 KB Output is correct
2 Correct 343 ms 37744 KB Output is correct
3 Correct 431 ms 37868 KB Output is correct
4 Correct 350 ms 37788 KB Output is correct
5 Correct 411 ms 37736 KB Output is correct
6 Correct 365 ms 37676 KB Output is correct
7 Correct 343 ms 37796 KB Output is correct
8 Correct 381 ms 37756 KB Output is correct
9 Correct 360 ms 37808 KB Output is correct
10 Correct 390 ms 37740 KB Output is correct
11 Correct 340 ms 37756 KB Output is correct
12 Correct 389 ms 37748 KB Output is correct
13 Correct 379 ms 37764 KB Output is correct
14 Correct 374 ms 37764 KB Output is correct
15 Correct 364 ms 37768 KB Output is correct
16 Correct 384 ms 37628 KB Output is correct
17 Correct 373 ms 37836 KB Output is correct
18 Correct 360 ms 37628 KB Output is correct
19 Correct 389 ms 37736 KB Output is correct
20 Correct 346 ms 37740 KB Output is correct
21 Correct 401 ms 37748 KB Output is correct
22 Correct 346 ms 38512 KB Output is correct
23 Correct 366 ms 38436 KB Output is correct
24 Correct 391 ms 38440 KB Output is correct
25 Correct 375 ms 38348 KB Output is correct
26 Correct 368 ms 38404 KB Output is correct
27 Correct 354 ms 38392 KB Output is correct
28 Correct 364 ms 38444 KB Output is correct
29 Correct 395 ms 38512 KB Output is correct
30 Correct 391 ms 38424 KB Output is correct
31 Correct 381 ms 38364 KB Output is correct
32 Correct 364 ms 38396 KB Output is correct
33 Correct 378 ms 38424 KB Output is correct
34 Correct 383 ms 38320 KB Output is correct
35 Correct 480 ms 38440 KB Output is correct
36 Correct 381 ms 38568 KB Output is correct
37 Correct 393 ms 38316 KB Output is correct
38 Correct 383 ms 38376 KB Output is correct
39 Correct 389 ms 38444 KB Output is correct
40 Correct 429 ms 38432 KB Output is correct
41 Correct 408 ms 38436 KB Output is correct
42 Correct 410 ms 38432 KB Output is correct
43 Correct 379 ms 38812 KB Output is correct
44 Correct 374 ms 38680 KB Output is correct
45 Correct 434 ms 38556 KB Output is correct
46 Correct 383 ms 38552 KB Output is correct
47 Correct 402 ms 38668 KB Output is correct
48 Correct 376 ms 38676 KB Output is correct
49 Correct 368 ms 38688 KB Output is correct
50 Correct 405 ms 38680 KB Output is correct
51 Correct 384 ms 38680 KB Output is correct
52 Correct 389 ms 38564 KB Output is correct
53 Correct 403 ms 38680 KB Output is correct
54 Correct 376 ms 38680 KB Output is correct
55 Correct 385 ms 38672 KB Output is correct
56 Correct 379 ms 38676 KB Output is correct
57 Correct 398 ms 38656 KB Output is correct
58 Correct 384 ms 38556 KB Output is correct
59 Correct 400 ms 38588 KB Output is correct
60 Correct 448 ms 38672 KB Output is correct
61 Correct 358 ms 38676 KB Output is correct
62 Correct 413 ms 38644 KB Output is correct
63 Correct 359 ms 38672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 427 ms 37764 KB Output is correct
2 Correct 343 ms 37744 KB Output is correct
3 Correct 431 ms 37868 KB Output is correct
4 Correct 350 ms 37788 KB Output is correct
5 Correct 411 ms 37736 KB Output is correct
6 Correct 365 ms 37676 KB Output is correct
7 Correct 343 ms 37796 KB Output is correct
8 Correct 381 ms 37756 KB Output is correct
9 Correct 360 ms 37808 KB Output is correct
10 Correct 390 ms 37740 KB Output is correct
11 Correct 340 ms 37756 KB Output is correct
12 Correct 389 ms 37748 KB Output is correct
13 Correct 379 ms 37764 KB Output is correct
14 Correct 374 ms 37764 KB Output is correct
15 Correct 364 ms 37768 KB Output is correct
16 Correct 384 ms 37628 KB Output is correct
17 Correct 373 ms 37836 KB Output is correct
18 Correct 360 ms 37628 KB Output is correct
19 Correct 389 ms 37736 KB Output is correct
20 Correct 346 ms 37740 KB Output is correct
21 Correct 401 ms 37748 KB Output is correct
22 Correct 346 ms 38512 KB Output is correct
23 Correct 366 ms 38436 KB Output is correct
24 Correct 391 ms 38440 KB Output is correct
25 Correct 375 ms 38348 KB Output is correct
26 Correct 368 ms 38404 KB Output is correct
27 Correct 354 ms 38392 KB Output is correct
28 Correct 364 ms 38444 KB Output is correct
29 Correct 395 ms 38512 KB Output is correct
30 Correct 391 ms 38424 KB Output is correct
31 Correct 381 ms 38364 KB Output is correct
32 Correct 364 ms 38396 KB Output is correct
33 Correct 378 ms 38424 KB Output is correct
34 Correct 383 ms 38320 KB Output is correct
35 Correct 480 ms 38440 KB Output is correct
36 Correct 381 ms 38568 KB Output is correct
37 Correct 393 ms 38316 KB Output is correct
38 Correct 383 ms 38376 KB Output is correct
39 Correct 389 ms 38444 KB Output is correct
40 Correct 429 ms 38432 KB Output is correct
41 Correct 408 ms 38436 KB Output is correct
42 Correct 410 ms 38432 KB Output is correct
43 Correct 379 ms 38812 KB Output is correct
44 Correct 374 ms 38680 KB Output is correct
45 Correct 434 ms 38556 KB Output is correct
46 Correct 383 ms 38552 KB Output is correct
47 Correct 402 ms 38668 KB Output is correct
48 Correct 376 ms 38676 KB Output is correct
49 Correct 368 ms 38688 KB Output is correct
50 Correct 405 ms 38680 KB Output is correct
51 Correct 384 ms 38680 KB Output is correct
52 Correct 389 ms 38564 KB Output is correct
53 Correct 403 ms 38680 KB Output is correct
54 Correct 376 ms 38680 KB Output is correct
55 Correct 385 ms 38672 KB Output is correct
56 Correct 379 ms 38676 KB Output is correct
57 Correct 398 ms 38656 KB Output is correct
58 Correct 384 ms 38556 KB Output is correct
59 Correct 400 ms 38588 KB Output is correct
60 Correct 448 ms 38672 KB Output is correct
61 Correct 358 ms 38676 KB Output is correct
62 Correct 413 ms 38644 KB Output is correct
63 Correct 359 ms 38672 KB Output is correct
64 Incorrect 418 ms 38916 KB Output isn't correct
65 Halted 0 ms 0 KB -