답안 #1093738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093738 2024-09-27T10:57:52 Z gyg Cubeword (CEOI19_cubeword) C++17
100 / 100
1077 ms 19008 KB
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define arr array
#define vct vector
#define str string
#define hset unordered_set
const int MX_N = 1e5 + 5, MD = 998244353;

int n;
arr<arr<arr<int, 67>, 67>, 13> cnt;

int md(int x) { return (x + MD) % MD; }

arr<arr<arr<int, 67>, 67>, 67> dp;
int cmp(int sz) {
    dp = {0};
    for (int i = 1; i <= 62; i++) 
        for (int j = 1; j <= 62; j++)
            for (int k = 1; k <= 62; k++)
                for (int l = 1; l <= 62; l++)
                    dp[i][j][k] = md(dp[i][j][k] + md(cnt[sz][i][l] * cnt[sz][j][l] * cnt[sz][k][l]));
     

    int ans = 0;
    for (int i = 1; i <= 62; i++) 
        for (int j = 1; j <= 62; j++)
            for (int k = 1; k <= 62; k++)
                for (int l = 1; l <= 62; l++)
                    ans = md(ans + md(dp[i][j][k] * dp[i][j][l]) * md(dp[i][k][l] * dp[j][k][l]));
    return ans;
}

signed main() {
    // freopen("cb.in", "r", stdin);
    cin.sync_with_stdio(false), cin.tie(0);
    cin >> n;
    hset<str> strs;
    for (int i = 1; i <= n; i++) {
        str x; cin >> x;
        strs.insert(x);
        reverse(x.begin(), x.end());
        strs.insert(x);
    }
    for (str x : strs) {
        auto indx = [](char x)->int {
            if ('a' <= x && x <= 'z') return x - 'a' + 1;
            if ('A' <= x && x <= 'Z') return 26 + x - 'A' + 1;
            return 52 + x - '0' + 1; 
        };
        cnt[x.size()][indx(x[0])][indx(x.back())]++;
    }
    
    int ans = 0;
    for (int i = 3; i <= 10; i++) {
        int nw_ans = cmp(i);
        ans = md(ans + nw_ans);
        // cout << i << ": " << nw_ans << endl;
    }   
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1006 ms 18032 KB Output is correct
2 Correct 1008 ms 18044 KB Output is correct
3 Correct 1008 ms 18044 KB Output is correct
4 Correct 1018 ms 18044 KB Output is correct
5 Correct 1004 ms 18048 KB Output is correct
6 Correct 1037 ms 17900 KB Output is correct
7 Correct 1010 ms 18040 KB Output is correct
8 Correct 1018 ms 18044 KB Output is correct
9 Correct 1027 ms 18040 KB Output is correct
10 Correct 1032 ms 18040 KB Output is correct
11 Correct 1077 ms 18052 KB Output is correct
12 Correct 1043 ms 18044 KB Output is correct
13 Correct 1014 ms 18048 KB Output is correct
14 Correct 1008 ms 17980 KB Output is correct
15 Correct 1012 ms 17984 KB Output is correct
16 Correct 1020 ms 18040 KB Output is correct
17 Correct 1012 ms 17816 KB Output is correct
18 Correct 1022 ms 18044 KB Output is correct
19 Correct 1008 ms 17848 KB Output is correct
20 Correct 1020 ms 18048 KB Output is correct
21 Correct 1012 ms 17832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1006 ms 18032 KB Output is correct
2 Correct 1008 ms 18044 KB Output is correct
3 Correct 1008 ms 18044 KB Output is correct
4 Correct 1018 ms 18044 KB Output is correct
5 Correct 1004 ms 18048 KB Output is correct
6 Correct 1037 ms 17900 KB Output is correct
7 Correct 1010 ms 18040 KB Output is correct
8 Correct 1018 ms 18044 KB Output is correct
9 Correct 1027 ms 18040 KB Output is correct
10 Correct 1032 ms 18040 KB Output is correct
11 Correct 1077 ms 18052 KB Output is correct
12 Correct 1043 ms 18044 KB Output is correct
13 Correct 1014 ms 18048 KB Output is correct
14 Correct 1008 ms 17980 KB Output is correct
15 Correct 1012 ms 17984 KB Output is correct
16 Correct 1020 ms 18040 KB Output is correct
17 Correct 1012 ms 17816 KB Output is correct
18 Correct 1022 ms 18044 KB Output is correct
19 Correct 1008 ms 17848 KB Output is correct
20 Correct 1020 ms 18048 KB Output is correct
21 Correct 1012 ms 17832 KB Output is correct
22 Correct 1027 ms 18300 KB Output is correct
23 Correct 1029 ms 18304 KB Output is correct
24 Correct 1036 ms 18548 KB Output is correct
25 Correct 1037 ms 18388 KB Output is correct
26 Correct 1020 ms 18300 KB Output is correct
27 Correct 1012 ms 18296 KB Output is correct
28 Correct 1012 ms 18504 KB Output is correct
29 Correct 1018 ms 18296 KB Output is correct
30 Correct 1010 ms 18288 KB Output is correct
31 Correct 1016 ms 18304 KB Output is correct
32 Correct 1014 ms 18304 KB Output is correct
33 Correct 1040 ms 18484 KB Output is correct
34 Correct 1006 ms 18500 KB Output is correct
35 Correct 1004 ms 18296 KB Output is correct
36 Correct 1004 ms 18504 KB Output is correct
37 Correct 1008 ms 18300 KB Output is correct
38 Correct 1028 ms 18400 KB Output is correct
39 Correct 1031 ms 18516 KB Output is correct
40 Correct 1020 ms 18528 KB Output is correct
41 Correct 1012 ms 18336 KB Output is correct
42 Correct 1014 ms 18296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1006 ms 18032 KB Output is correct
2 Correct 1008 ms 18044 KB Output is correct
3 Correct 1008 ms 18044 KB Output is correct
4 Correct 1018 ms 18044 KB Output is correct
5 Correct 1004 ms 18048 KB Output is correct
6 Correct 1037 ms 17900 KB Output is correct
7 Correct 1010 ms 18040 KB Output is correct
8 Correct 1018 ms 18044 KB Output is correct
9 Correct 1027 ms 18040 KB Output is correct
10 Correct 1032 ms 18040 KB Output is correct
11 Correct 1077 ms 18052 KB Output is correct
12 Correct 1043 ms 18044 KB Output is correct
13 Correct 1014 ms 18048 KB Output is correct
14 Correct 1008 ms 17980 KB Output is correct
15 Correct 1012 ms 17984 KB Output is correct
16 Correct 1020 ms 18040 KB Output is correct
17 Correct 1012 ms 17816 KB Output is correct
18 Correct 1022 ms 18044 KB Output is correct
19 Correct 1008 ms 17848 KB Output is correct
20 Correct 1020 ms 18048 KB Output is correct
21 Correct 1012 ms 17832 KB Output is correct
22 Correct 1027 ms 18300 KB Output is correct
23 Correct 1029 ms 18304 KB Output is correct
24 Correct 1036 ms 18548 KB Output is correct
25 Correct 1037 ms 18388 KB Output is correct
26 Correct 1020 ms 18300 KB Output is correct
27 Correct 1012 ms 18296 KB Output is correct
28 Correct 1012 ms 18504 KB Output is correct
29 Correct 1018 ms 18296 KB Output is correct
30 Correct 1010 ms 18288 KB Output is correct
31 Correct 1016 ms 18304 KB Output is correct
32 Correct 1014 ms 18304 KB Output is correct
33 Correct 1040 ms 18484 KB Output is correct
34 Correct 1006 ms 18500 KB Output is correct
35 Correct 1004 ms 18296 KB Output is correct
36 Correct 1004 ms 18504 KB Output is correct
37 Correct 1008 ms 18300 KB Output is correct
38 Correct 1028 ms 18400 KB Output is correct
39 Correct 1031 ms 18516 KB Output is correct
40 Correct 1020 ms 18528 KB Output is correct
41 Correct 1012 ms 18336 KB Output is correct
42 Correct 1014 ms 18296 KB Output is correct
43 Correct 1008 ms 18560 KB Output is correct
44 Correct 1028 ms 18600 KB Output is correct
45 Correct 1024 ms 18532 KB Output is correct
46 Correct 1008 ms 18744 KB Output is correct
47 Correct 1024 ms 18556 KB Output is correct
48 Correct 1008 ms 18752 KB Output is correct
49 Correct 1010 ms 18560 KB Output is correct
50 Correct 1010 ms 18560 KB Output is correct
51 Correct 1014 ms 18552 KB Output is correct
52 Correct 1030 ms 18628 KB Output is correct
53 Correct 1010 ms 18560 KB Output is correct
54 Correct 1008 ms 18652 KB Output is correct
55 Correct 1012 ms 18564 KB Output is correct
56 Correct 1014 ms 18644 KB Output is correct
57 Correct 1006 ms 18556 KB Output is correct
58 Correct 1002 ms 18732 KB Output is correct
59 Correct 1006 ms 18556 KB Output is correct
60 Correct 1008 ms 18556 KB Output is correct
61 Correct 1008 ms 18560 KB Output is correct
62 Correct 1010 ms 18552 KB Output is correct
63 Correct 1016 ms 18552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1006 ms 18032 KB Output is correct
2 Correct 1008 ms 18044 KB Output is correct
3 Correct 1008 ms 18044 KB Output is correct
4 Correct 1018 ms 18044 KB Output is correct
5 Correct 1004 ms 18048 KB Output is correct
6 Correct 1037 ms 17900 KB Output is correct
7 Correct 1010 ms 18040 KB Output is correct
8 Correct 1018 ms 18044 KB Output is correct
9 Correct 1027 ms 18040 KB Output is correct
10 Correct 1032 ms 18040 KB Output is correct
11 Correct 1077 ms 18052 KB Output is correct
12 Correct 1043 ms 18044 KB Output is correct
13 Correct 1014 ms 18048 KB Output is correct
14 Correct 1008 ms 17980 KB Output is correct
15 Correct 1012 ms 17984 KB Output is correct
16 Correct 1020 ms 18040 KB Output is correct
17 Correct 1012 ms 17816 KB Output is correct
18 Correct 1022 ms 18044 KB Output is correct
19 Correct 1008 ms 17848 KB Output is correct
20 Correct 1020 ms 18048 KB Output is correct
21 Correct 1012 ms 17832 KB Output is correct
22 Correct 1027 ms 18300 KB Output is correct
23 Correct 1029 ms 18304 KB Output is correct
24 Correct 1036 ms 18548 KB Output is correct
25 Correct 1037 ms 18388 KB Output is correct
26 Correct 1020 ms 18300 KB Output is correct
27 Correct 1012 ms 18296 KB Output is correct
28 Correct 1012 ms 18504 KB Output is correct
29 Correct 1018 ms 18296 KB Output is correct
30 Correct 1010 ms 18288 KB Output is correct
31 Correct 1016 ms 18304 KB Output is correct
32 Correct 1014 ms 18304 KB Output is correct
33 Correct 1040 ms 18484 KB Output is correct
34 Correct 1006 ms 18500 KB Output is correct
35 Correct 1004 ms 18296 KB Output is correct
36 Correct 1004 ms 18504 KB Output is correct
37 Correct 1008 ms 18300 KB Output is correct
38 Correct 1028 ms 18400 KB Output is correct
39 Correct 1031 ms 18516 KB Output is correct
40 Correct 1020 ms 18528 KB Output is correct
41 Correct 1012 ms 18336 KB Output is correct
42 Correct 1014 ms 18296 KB Output is correct
43 Correct 1008 ms 18560 KB Output is correct
44 Correct 1028 ms 18600 KB Output is correct
45 Correct 1024 ms 18532 KB Output is correct
46 Correct 1008 ms 18744 KB Output is correct
47 Correct 1024 ms 18556 KB Output is correct
48 Correct 1008 ms 18752 KB Output is correct
49 Correct 1010 ms 18560 KB Output is correct
50 Correct 1010 ms 18560 KB Output is correct
51 Correct 1014 ms 18552 KB Output is correct
52 Correct 1030 ms 18628 KB Output is correct
53 Correct 1010 ms 18560 KB Output is correct
54 Correct 1008 ms 18652 KB Output is correct
55 Correct 1012 ms 18564 KB Output is correct
56 Correct 1014 ms 18644 KB Output is correct
57 Correct 1006 ms 18556 KB Output is correct
58 Correct 1002 ms 18732 KB Output is correct
59 Correct 1006 ms 18556 KB Output is correct
60 Correct 1008 ms 18556 KB Output is correct
61 Correct 1008 ms 18560 KB Output is correct
62 Correct 1010 ms 18552 KB Output is correct
63 Correct 1016 ms 18552 KB Output is correct
64 Correct 1016 ms 19008 KB Output is correct
65 Correct 1008 ms 18808 KB Output is correct
66 Correct 1006 ms 18932 KB Output is correct
67 Correct 1027 ms 18816 KB Output is correct
68 Correct 1053 ms 18812 KB Output is correct
69 Correct 1053 ms 18940 KB Output is correct
70 Correct 1040 ms 18816 KB Output is correct
71 Correct 1016 ms 18996 KB Output is correct
72 Correct 1006 ms 18884 KB Output is correct
73 Correct 1010 ms 18812 KB Output is correct
74 Correct 1008 ms 18812 KB Output is correct
75 Correct 1004 ms 18812 KB Output is correct
76 Correct 1006 ms 18816 KB Output is correct
77 Correct 1012 ms 18816 KB Output is correct
78 Correct 1008 ms 18816 KB Output is correct
79 Correct 1006 ms 18816 KB Output is correct
80 Correct 1006 ms 18812 KB Output is correct
81 Correct 1016 ms 18812 KB Output is correct
82 Correct 1006 ms 18812 KB Output is correct
83 Correct 1006 ms 18936 KB Output is correct
84 Correct 1010 ms 18808 KB Output is correct