답안 #546625

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
546625 2022-04-07T21:42:31 Z LucaDantas Cubeword (CEOI19_cubeword) C++17
100 / 100
431 ms 39776 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 >= '0' && c <= '9') return c-'0'+52; if(c >= 'a') return c-'a'; return 26+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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 397 ms 37736 KB Output is correct
2 Correct 369 ms 37872 KB Output is correct
3 Correct 375 ms 37756 KB Output is correct
4 Correct 386 ms 37708 KB Output is correct
5 Correct 393 ms 37756 KB Output is correct
6 Correct 397 ms 37712 KB Output is correct
7 Correct 378 ms 37708 KB Output is correct
8 Correct 384 ms 37816 KB Output is correct
9 Correct 390 ms 37708 KB Output is correct
10 Correct 389 ms 37684 KB Output is correct
11 Correct 403 ms 37716 KB Output is correct
12 Correct 387 ms 37712 KB Output is correct
13 Correct 374 ms 37768 KB Output is correct
14 Correct 414 ms 37760 KB Output is correct
15 Correct 372 ms 37672 KB Output is correct
16 Correct 389 ms 37724 KB Output is correct
17 Correct 396 ms 37756 KB Output is correct
18 Correct 374 ms 37768 KB Output is correct
19 Correct 376 ms 37740 KB Output is correct
20 Correct 377 ms 37760 KB Output is correct
21 Correct 393 ms 37744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 397 ms 37736 KB Output is correct
2 Correct 369 ms 37872 KB Output is correct
3 Correct 375 ms 37756 KB Output is correct
4 Correct 386 ms 37708 KB Output is correct
5 Correct 393 ms 37756 KB Output is correct
6 Correct 397 ms 37712 KB Output is correct
7 Correct 378 ms 37708 KB Output is correct
8 Correct 384 ms 37816 KB Output is correct
9 Correct 390 ms 37708 KB Output is correct
10 Correct 389 ms 37684 KB Output is correct
11 Correct 403 ms 37716 KB Output is correct
12 Correct 387 ms 37712 KB Output is correct
13 Correct 374 ms 37768 KB Output is correct
14 Correct 414 ms 37760 KB Output is correct
15 Correct 372 ms 37672 KB Output is correct
16 Correct 389 ms 37724 KB Output is correct
17 Correct 396 ms 37756 KB Output is correct
18 Correct 374 ms 37768 KB Output is correct
19 Correct 376 ms 37740 KB Output is correct
20 Correct 377 ms 37760 KB Output is correct
21 Correct 393 ms 37744 KB Output is correct
22 Correct 382 ms 38440 KB Output is correct
23 Correct 384 ms 38340 KB Output is correct
24 Correct 365 ms 38500 KB Output is correct
25 Correct 364 ms 38428 KB Output is correct
26 Correct 376 ms 38424 KB Output is correct
27 Correct 371 ms 38468 KB Output is correct
28 Correct 394 ms 38360 KB Output is correct
29 Correct 381 ms 38564 KB Output is correct
30 Correct 392 ms 38368 KB Output is correct
31 Correct 376 ms 38436 KB Output is correct
32 Correct 359 ms 38420 KB Output is correct
33 Correct 387 ms 38476 KB Output is correct
34 Correct 397 ms 38436 KB Output is correct
35 Correct 388 ms 38432 KB Output is correct
36 Correct 368 ms 38436 KB Output is correct
37 Correct 389 ms 38432 KB Output is correct
38 Correct 377 ms 38380 KB Output is correct
39 Correct 388 ms 38552 KB Output is correct
40 Correct 376 ms 38428 KB Output is correct
41 Correct 404 ms 38516 KB Output is correct
42 Correct 377 ms 38340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 397 ms 37736 KB Output is correct
2 Correct 369 ms 37872 KB Output is correct
3 Correct 375 ms 37756 KB Output is correct
4 Correct 386 ms 37708 KB Output is correct
5 Correct 393 ms 37756 KB Output is correct
6 Correct 397 ms 37712 KB Output is correct
7 Correct 378 ms 37708 KB Output is correct
8 Correct 384 ms 37816 KB Output is correct
9 Correct 390 ms 37708 KB Output is correct
10 Correct 389 ms 37684 KB Output is correct
11 Correct 403 ms 37716 KB Output is correct
12 Correct 387 ms 37712 KB Output is correct
13 Correct 374 ms 37768 KB Output is correct
14 Correct 414 ms 37760 KB Output is correct
15 Correct 372 ms 37672 KB Output is correct
16 Correct 389 ms 37724 KB Output is correct
17 Correct 396 ms 37756 KB Output is correct
18 Correct 374 ms 37768 KB Output is correct
19 Correct 376 ms 37740 KB Output is correct
20 Correct 377 ms 37760 KB Output is correct
21 Correct 393 ms 37744 KB Output is correct
22 Correct 382 ms 38440 KB Output is correct
23 Correct 384 ms 38340 KB Output is correct
24 Correct 365 ms 38500 KB Output is correct
25 Correct 364 ms 38428 KB Output is correct
26 Correct 376 ms 38424 KB Output is correct
27 Correct 371 ms 38468 KB Output is correct
28 Correct 394 ms 38360 KB Output is correct
29 Correct 381 ms 38564 KB Output is correct
30 Correct 392 ms 38368 KB Output is correct
31 Correct 376 ms 38436 KB Output is correct
32 Correct 359 ms 38420 KB Output is correct
33 Correct 387 ms 38476 KB Output is correct
34 Correct 397 ms 38436 KB Output is correct
35 Correct 388 ms 38432 KB Output is correct
36 Correct 368 ms 38436 KB Output is correct
37 Correct 389 ms 38432 KB Output is correct
38 Correct 377 ms 38380 KB Output is correct
39 Correct 388 ms 38552 KB Output is correct
40 Correct 376 ms 38428 KB Output is correct
41 Correct 404 ms 38516 KB Output is correct
42 Correct 377 ms 38340 KB Output is correct
43 Correct 356 ms 38600 KB Output is correct
44 Correct 377 ms 38796 KB Output is correct
45 Correct 357 ms 38604 KB Output is correct
46 Correct 399 ms 38588 KB Output is correct
47 Correct 357 ms 38772 KB Output is correct
48 Correct 382 ms 38796 KB Output is correct
49 Correct 367 ms 38712 KB Output is correct
50 Correct 375 ms 38660 KB Output is correct
51 Correct 368 ms 38696 KB Output is correct
52 Correct 431 ms 38648 KB Output is correct
53 Correct 372 ms 38752 KB Output is correct
54 Correct 388 ms 38896 KB Output is correct
55 Correct 369 ms 38584 KB Output is correct
56 Correct 379 ms 38704 KB Output is correct
57 Correct 373 ms 38600 KB Output is correct
58 Correct 379 ms 38620 KB Output is correct
59 Correct 373 ms 38704 KB Output is correct
60 Correct 360 ms 38696 KB Output is correct
61 Correct 410 ms 38692 KB Output is correct
62 Correct 351 ms 38644 KB Output is correct
63 Correct 402 ms 38640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 397 ms 37736 KB Output is correct
2 Correct 369 ms 37872 KB Output is correct
3 Correct 375 ms 37756 KB Output is correct
4 Correct 386 ms 37708 KB Output is correct
5 Correct 393 ms 37756 KB Output is correct
6 Correct 397 ms 37712 KB Output is correct
7 Correct 378 ms 37708 KB Output is correct
8 Correct 384 ms 37816 KB Output is correct
9 Correct 390 ms 37708 KB Output is correct
10 Correct 389 ms 37684 KB Output is correct
11 Correct 403 ms 37716 KB Output is correct
12 Correct 387 ms 37712 KB Output is correct
13 Correct 374 ms 37768 KB Output is correct
14 Correct 414 ms 37760 KB Output is correct
15 Correct 372 ms 37672 KB Output is correct
16 Correct 389 ms 37724 KB Output is correct
17 Correct 396 ms 37756 KB Output is correct
18 Correct 374 ms 37768 KB Output is correct
19 Correct 376 ms 37740 KB Output is correct
20 Correct 377 ms 37760 KB Output is correct
21 Correct 393 ms 37744 KB Output is correct
22 Correct 382 ms 38440 KB Output is correct
23 Correct 384 ms 38340 KB Output is correct
24 Correct 365 ms 38500 KB Output is correct
25 Correct 364 ms 38428 KB Output is correct
26 Correct 376 ms 38424 KB Output is correct
27 Correct 371 ms 38468 KB Output is correct
28 Correct 394 ms 38360 KB Output is correct
29 Correct 381 ms 38564 KB Output is correct
30 Correct 392 ms 38368 KB Output is correct
31 Correct 376 ms 38436 KB Output is correct
32 Correct 359 ms 38420 KB Output is correct
33 Correct 387 ms 38476 KB Output is correct
34 Correct 397 ms 38436 KB Output is correct
35 Correct 388 ms 38432 KB Output is correct
36 Correct 368 ms 38436 KB Output is correct
37 Correct 389 ms 38432 KB Output is correct
38 Correct 377 ms 38380 KB Output is correct
39 Correct 388 ms 38552 KB Output is correct
40 Correct 376 ms 38428 KB Output is correct
41 Correct 404 ms 38516 KB Output is correct
42 Correct 377 ms 38340 KB Output is correct
43 Correct 356 ms 38600 KB Output is correct
44 Correct 377 ms 38796 KB Output is correct
45 Correct 357 ms 38604 KB Output is correct
46 Correct 399 ms 38588 KB Output is correct
47 Correct 357 ms 38772 KB Output is correct
48 Correct 382 ms 38796 KB Output is correct
49 Correct 367 ms 38712 KB Output is correct
50 Correct 375 ms 38660 KB Output is correct
51 Correct 368 ms 38696 KB Output is correct
52 Correct 431 ms 38648 KB Output is correct
53 Correct 372 ms 38752 KB Output is correct
54 Correct 388 ms 38896 KB Output is correct
55 Correct 369 ms 38584 KB Output is correct
56 Correct 379 ms 38704 KB Output is correct
57 Correct 373 ms 38600 KB Output is correct
58 Correct 379 ms 38620 KB Output is correct
59 Correct 373 ms 38704 KB Output is correct
60 Correct 360 ms 38696 KB Output is correct
61 Correct 410 ms 38692 KB Output is correct
62 Correct 351 ms 38644 KB Output is correct
63 Correct 402 ms 38640 KB Output is correct
64 Correct 363 ms 38928 KB Output is correct
65 Correct 412 ms 39676 KB Output is correct
66 Correct 375 ms 39776 KB Output is correct
67 Correct 368 ms 39676 KB Output is correct
68 Correct 390 ms 39676 KB Output is correct
69 Correct 360 ms 39676 KB Output is correct
70 Correct 387 ms 39668 KB Output is correct
71 Correct 359 ms 39632 KB Output is correct
72 Correct 380 ms 39672 KB Output is correct
73 Correct 367 ms 39612 KB Output is correct
74 Correct 393 ms 39592 KB Output is correct
75 Correct 373 ms 39624 KB Output is correct
76 Correct 387 ms 39592 KB Output is correct
77 Correct 383 ms 39776 KB Output is correct
78 Correct 364 ms 39564 KB Output is correct
79 Correct 400 ms 39580 KB Output is correct
80 Correct 369 ms 39620 KB Output is correct
81 Correct 420 ms 39672 KB Output is correct
82 Correct 363 ms 39588 KB Output is correct
83 Correct 396 ms 39640 KB Output is correct
84 Correct 391 ms 39616 KB Output is correct