답안 #779841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779841 2023-07-12T01:00:08 Z Hacv16 Cubeword (CEOI19_cubeword) C++17
100 / 100
1010 ms 18240 KB
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") 

#define int long long int
const int ALP = 62;
const int MOD = 998244353;
 
unordered_set<string> s[15];
 
int32_t main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    int n; cin >> n;
 
    for(int i = 1; i <= n; i++){
        string cur; cin >> cur;
 
        s[cur.size()].emplace(cur);
        reverse(cur.begin(), cur.end());
        s[cur.size()].emplace(cur);
    }
 
    auto getId = [&](char c)
    {
        if(c <= '9') return c - '0';
        if(c <= 'Z') return ('9' - '0' + 1) + c - 'A';
        return ('9' - '0' + 1) + ('Z' - 'A') + 1 + c - 'a';
    };
 
    auto solve = [&](int tam)
    {
        int dp[ALP][ALP][ALP] = { 0 };
        int freq[ALP][ALP] = { 0 };
 
        for(auto x : s[tam]){
            int i = getId(x[0]), j = getId(x.back());
            freq[i][j]++;
        }
 
        for(int a = 0; a < ALP; a++)
            for(int b = 0; b < ALP; b++)
                for(int c = 0; c < ALP; c++)
                    for(int i = 0; i < ALP; i++)
                        dp[a][b][c] = (dp[a][b][c] + (freq[a][i] * freq[b][i] * freq[c][i]) % MOD) % MOD;
 
        int ret = 0;
 
        for(int a = 0; a < ALP; a++){
            for(int b = 0; b < ALP; b++){
                for(int c = 0; c < ALP; c++){
                    for(int d = 0; d < ALP; d++){
                        int curAdd = 1;
 
                        curAdd = (curAdd * dp[a][b][c]) % MOD;
                        curAdd = (curAdd * dp[b][c][d]) % MOD;
                        curAdd = (curAdd * dp[a][b][d]) % MOD;
                        curAdd = (curAdd * dp[a][c][d]) % MOD;
 
                        ret += curAdd;
                    }
                }
            }
        }
 
        return ret;
    };
 
    int ans = 0;
 
    for(int i = 1; i <= 10; i++)
    {
        if(s[i].empty()) continue;
        ans = (ans + solve(i)) % MOD;
    }
 
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 984 ms 16428 KB Output is correct
2 Correct 959 ms 16420 KB Output is correct
3 Correct 970 ms 16428 KB Output is correct
4 Correct 960 ms 16416 KB Output is correct
5 Correct 964 ms 16424 KB Output is correct
6 Correct 963 ms 16440 KB Output is correct
7 Correct 965 ms 16436 KB Output is correct
8 Correct 987 ms 16428 KB Output is correct
9 Correct 977 ms 16408 KB Output is correct
10 Correct 962 ms 16432 KB Output is correct
11 Correct 964 ms 16424 KB Output is correct
12 Correct 967 ms 16416 KB Output is correct
13 Correct 989 ms 16436 KB Output is correct
14 Correct 962 ms 16432 KB Output is correct
15 Correct 964 ms 16440 KB Output is correct
16 Correct 986 ms 16420 KB Output is correct
17 Correct 951 ms 16424 KB Output is correct
18 Correct 961 ms 16416 KB Output is correct
19 Correct 975 ms 16408 KB Output is correct
20 Correct 958 ms 16432 KB Output is correct
21 Correct 962 ms 16408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 984 ms 16428 KB Output is correct
2 Correct 959 ms 16420 KB Output is correct
3 Correct 970 ms 16428 KB Output is correct
4 Correct 960 ms 16416 KB Output is correct
5 Correct 964 ms 16424 KB Output is correct
6 Correct 963 ms 16440 KB Output is correct
7 Correct 965 ms 16436 KB Output is correct
8 Correct 987 ms 16428 KB Output is correct
9 Correct 977 ms 16408 KB Output is correct
10 Correct 962 ms 16432 KB Output is correct
11 Correct 964 ms 16424 KB Output is correct
12 Correct 967 ms 16416 KB Output is correct
13 Correct 989 ms 16436 KB Output is correct
14 Correct 962 ms 16432 KB Output is correct
15 Correct 964 ms 16440 KB Output is correct
16 Correct 986 ms 16420 KB Output is correct
17 Correct 951 ms 16424 KB Output is correct
18 Correct 961 ms 16416 KB Output is correct
19 Correct 975 ms 16408 KB Output is correct
20 Correct 958 ms 16432 KB Output is correct
21 Correct 962 ms 16408 KB Output is correct
22 Correct 970 ms 17476 KB Output is correct
23 Correct 956 ms 17468 KB Output is correct
24 Correct 1002 ms 17480 KB Output is correct
25 Correct 993 ms 17488 KB Output is correct
26 Correct 1010 ms 17460 KB Output is correct
27 Correct 955 ms 17460 KB Output is correct
28 Correct 994 ms 17472 KB Output is correct
29 Correct 989 ms 17480 KB Output is correct
30 Correct 998 ms 17472 KB Output is correct
31 Correct 960 ms 17476 KB Output is correct
32 Correct 970 ms 17456 KB Output is correct
33 Correct 983 ms 17532 KB Output is correct
34 Correct 961 ms 17488 KB Output is correct
35 Correct 967 ms 17476 KB Output is correct
36 Correct 970 ms 17476 KB Output is correct
37 Correct 960 ms 17472 KB Output is correct
38 Correct 983 ms 17492 KB Output is correct
39 Correct 965 ms 17476 KB Output is correct
40 Correct 960 ms 17488 KB Output is correct
41 Correct 971 ms 17468 KB Output is correct
42 Correct 967 ms 17472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 984 ms 16428 KB Output is correct
2 Correct 959 ms 16420 KB Output is correct
3 Correct 970 ms 16428 KB Output is correct
4 Correct 960 ms 16416 KB Output is correct
5 Correct 964 ms 16424 KB Output is correct
6 Correct 963 ms 16440 KB Output is correct
7 Correct 965 ms 16436 KB Output is correct
8 Correct 987 ms 16428 KB Output is correct
9 Correct 977 ms 16408 KB Output is correct
10 Correct 962 ms 16432 KB Output is correct
11 Correct 964 ms 16424 KB Output is correct
12 Correct 967 ms 16416 KB Output is correct
13 Correct 989 ms 16436 KB Output is correct
14 Correct 962 ms 16432 KB Output is correct
15 Correct 964 ms 16440 KB Output is correct
16 Correct 986 ms 16420 KB Output is correct
17 Correct 951 ms 16424 KB Output is correct
18 Correct 961 ms 16416 KB Output is correct
19 Correct 975 ms 16408 KB Output is correct
20 Correct 958 ms 16432 KB Output is correct
21 Correct 962 ms 16408 KB Output is correct
22 Correct 970 ms 17476 KB Output is correct
23 Correct 956 ms 17468 KB Output is correct
24 Correct 1002 ms 17480 KB Output is correct
25 Correct 993 ms 17488 KB Output is correct
26 Correct 1010 ms 17460 KB Output is correct
27 Correct 955 ms 17460 KB Output is correct
28 Correct 994 ms 17472 KB Output is correct
29 Correct 989 ms 17480 KB Output is correct
30 Correct 998 ms 17472 KB Output is correct
31 Correct 960 ms 17476 KB Output is correct
32 Correct 970 ms 17456 KB Output is correct
33 Correct 983 ms 17532 KB Output is correct
34 Correct 961 ms 17488 KB Output is correct
35 Correct 967 ms 17476 KB Output is correct
36 Correct 970 ms 17476 KB Output is correct
37 Correct 960 ms 17472 KB Output is correct
38 Correct 983 ms 17492 KB Output is correct
39 Correct 965 ms 17476 KB Output is correct
40 Correct 960 ms 17488 KB Output is correct
41 Correct 971 ms 17468 KB Output is correct
42 Correct 967 ms 17472 KB Output is correct
43 Correct 960 ms 17740 KB Output is correct
44 Correct 989 ms 17756 KB Output is correct
45 Correct 977 ms 17712 KB Output is correct
46 Correct 963 ms 17732 KB Output is correct
47 Correct 960 ms 17616 KB Output is correct
48 Correct 965 ms 17740 KB Output is correct
49 Correct 959 ms 17672 KB Output is correct
50 Correct 971 ms 17740 KB Output is correct
51 Correct 978 ms 17736 KB Output is correct
52 Correct 964 ms 17732 KB Output is correct
53 Correct 965 ms 17748 KB Output is correct
54 Correct 962 ms 17744 KB Output is correct
55 Correct 969 ms 17732 KB Output is correct
56 Correct 972 ms 17736 KB Output is correct
57 Correct 1002 ms 17720 KB Output is correct
58 Correct 974 ms 17740 KB Output is correct
59 Correct 980 ms 17736 KB Output is correct
60 Correct 962 ms 17708 KB Output is correct
61 Correct 985 ms 17740 KB Output is correct
62 Correct 983 ms 17728 KB Output is correct
63 Correct 960 ms 17744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 984 ms 16428 KB Output is correct
2 Correct 959 ms 16420 KB Output is correct
3 Correct 970 ms 16428 KB Output is correct
4 Correct 960 ms 16416 KB Output is correct
5 Correct 964 ms 16424 KB Output is correct
6 Correct 963 ms 16440 KB Output is correct
7 Correct 965 ms 16436 KB Output is correct
8 Correct 987 ms 16428 KB Output is correct
9 Correct 977 ms 16408 KB Output is correct
10 Correct 962 ms 16432 KB Output is correct
11 Correct 964 ms 16424 KB Output is correct
12 Correct 967 ms 16416 KB Output is correct
13 Correct 989 ms 16436 KB Output is correct
14 Correct 962 ms 16432 KB Output is correct
15 Correct 964 ms 16440 KB Output is correct
16 Correct 986 ms 16420 KB Output is correct
17 Correct 951 ms 16424 KB Output is correct
18 Correct 961 ms 16416 KB Output is correct
19 Correct 975 ms 16408 KB Output is correct
20 Correct 958 ms 16432 KB Output is correct
21 Correct 962 ms 16408 KB Output is correct
22 Correct 970 ms 17476 KB Output is correct
23 Correct 956 ms 17468 KB Output is correct
24 Correct 1002 ms 17480 KB Output is correct
25 Correct 993 ms 17488 KB Output is correct
26 Correct 1010 ms 17460 KB Output is correct
27 Correct 955 ms 17460 KB Output is correct
28 Correct 994 ms 17472 KB Output is correct
29 Correct 989 ms 17480 KB Output is correct
30 Correct 998 ms 17472 KB Output is correct
31 Correct 960 ms 17476 KB Output is correct
32 Correct 970 ms 17456 KB Output is correct
33 Correct 983 ms 17532 KB Output is correct
34 Correct 961 ms 17488 KB Output is correct
35 Correct 967 ms 17476 KB Output is correct
36 Correct 970 ms 17476 KB Output is correct
37 Correct 960 ms 17472 KB Output is correct
38 Correct 983 ms 17492 KB Output is correct
39 Correct 965 ms 17476 KB Output is correct
40 Correct 960 ms 17488 KB Output is correct
41 Correct 971 ms 17468 KB Output is correct
42 Correct 967 ms 17472 KB Output is correct
43 Correct 960 ms 17740 KB Output is correct
44 Correct 989 ms 17756 KB Output is correct
45 Correct 977 ms 17712 KB Output is correct
46 Correct 963 ms 17732 KB Output is correct
47 Correct 960 ms 17616 KB Output is correct
48 Correct 965 ms 17740 KB Output is correct
49 Correct 959 ms 17672 KB Output is correct
50 Correct 971 ms 17740 KB Output is correct
51 Correct 978 ms 17736 KB Output is correct
52 Correct 964 ms 17732 KB Output is correct
53 Correct 965 ms 17748 KB Output is correct
54 Correct 962 ms 17744 KB Output is correct
55 Correct 969 ms 17732 KB Output is correct
56 Correct 972 ms 17736 KB Output is correct
57 Correct 1002 ms 17720 KB Output is correct
58 Correct 974 ms 17740 KB Output is correct
59 Correct 980 ms 17736 KB Output is correct
60 Correct 962 ms 17708 KB Output is correct
61 Correct 985 ms 17740 KB Output is correct
62 Correct 983 ms 17728 KB Output is correct
63 Correct 960 ms 17744 KB Output is correct
64 Correct 994 ms 18240 KB Output is correct
65 Correct 976 ms 18092 KB Output is correct
66 Correct 977 ms 18096 KB Output is correct
67 Correct 968 ms 18088 KB Output is correct
68 Correct 962 ms 18088 KB Output is correct
69 Correct 964 ms 18092 KB Output is correct
70 Correct 954 ms 18088 KB Output is correct
71 Correct 992 ms 17972 KB Output is correct
72 Correct 981 ms 18088 KB Output is correct
73 Correct 966 ms 18088 KB Output is correct
74 Correct 979 ms 18108 KB Output is correct
75 Correct 947 ms 18084 KB Output is correct
76 Correct 954 ms 18080 KB Output is correct
77 Correct 983 ms 18092 KB Output is correct
78 Correct 963 ms 18084 KB Output is correct
79 Correct 963 ms 18084 KB Output is correct
80 Correct 995 ms 18088 KB Output is correct
81 Correct 984 ms 18084 KB Output is correct
82 Correct 960 ms 18080 KB Output is correct
83 Correct 960 ms 18124 KB Output is correct
84 Correct 982 ms 18084 KB Output is correct