Submission #779516

# Submission time Handle Problem Language Result Execution time Memory
779516 2023-07-11T13:41:10 Z Hacv16 Cubeword (CEOI19_cubeword) C++17
100 / 100
1024 ms 17484 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long int
const int ALP = 62;
const int MOD = 998244353;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

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';
}
# Verdict Execution time Memory Grader output
1 Correct 967 ms 15568 KB Output is correct
2 Correct 966 ms 15568 KB Output is correct
3 Correct 953 ms 15640 KB Output is correct
4 Correct 952 ms 15648 KB Output is correct
5 Correct 957 ms 15512 KB Output is correct
6 Correct 958 ms 15564 KB Output is correct
7 Correct 960 ms 15580 KB Output is correct
8 Correct 963 ms 15568 KB Output is correct
9 Correct 965 ms 15636 KB Output is correct
10 Correct 956 ms 15588 KB Output is correct
11 Correct 956 ms 15564 KB Output is correct
12 Correct 952 ms 15552 KB Output is correct
13 Correct 960 ms 15640 KB Output is correct
14 Correct 962 ms 15568 KB Output is correct
15 Correct 962 ms 15568 KB Output is correct
16 Correct 961 ms 15560 KB Output is correct
17 Correct 955 ms 15572 KB Output is correct
18 Correct 953 ms 15560 KB Output is correct
19 Correct 962 ms 15556 KB Output is correct
20 Correct 957 ms 15640 KB Output is correct
21 Correct 955 ms 15608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 967 ms 15568 KB Output is correct
2 Correct 966 ms 15568 KB Output is correct
3 Correct 953 ms 15640 KB Output is correct
4 Correct 952 ms 15648 KB Output is correct
5 Correct 957 ms 15512 KB Output is correct
6 Correct 958 ms 15564 KB Output is correct
7 Correct 960 ms 15580 KB Output is correct
8 Correct 963 ms 15568 KB Output is correct
9 Correct 965 ms 15636 KB Output is correct
10 Correct 956 ms 15588 KB Output is correct
11 Correct 956 ms 15564 KB Output is correct
12 Correct 952 ms 15552 KB Output is correct
13 Correct 960 ms 15640 KB Output is correct
14 Correct 962 ms 15568 KB Output is correct
15 Correct 962 ms 15568 KB Output is correct
16 Correct 961 ms 15560 KB Output is correct
17 Correct 955 ms 15572 KB Output is correct
18 Correct 953 ms 15560 KB Output is correct
19 Correct 962 ms 15556 KB Output is correct
20 Correct 957 ms 15640 KB Output is correct
21 Correct 955 ms 15608 KB Output is correct
22 Correct 959 ms 16712 KB Output is correct
23 Correct 989 ms 16692 KB Output is correct
24 Correct 971 ms 16708 KB Output is correct
25 Correct 970 ms 16696 KB Output is correct
26 Correct 966 ms 16696 KB Output is correct
27 Correct 1012 ms 16692 KB Output is correct
28 Correct 967 ms 16708 KB Output is correct
29 Correct 968 ms 16708 KB Output is correct
30 Correct 964 ms 16784 KB Output is correct
31 Correct 962 ms 16696 KB Output is correct
32 Correct 949 ms 16688 KB Output is correct
33 Correct 959 ms 16700 KB Output is correct
34 Correct 950 ms 16704 KB Output is correct
35 Correct 958 ms 16744 KB Output is correct
36 Correct 975 ms 16700 KB Output is correct
37 Correct 967 ms 16704 KB Output is correct
38 Correct 951 ms 16644 KB Output is correct
39 Correct 957 ms 16696 KB Output is correct
40 Correct 960 ms 16704 KB Output is correct
41 Correct 968 ms 16700 KB Output is correct
42 Correct 953 ms 16704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 967 ms 15568 KB Output is correct
2 Correct 966 ms 15568 KB Output is correct
3 Correct 953 ms 15640 KB Output is correct
4 Correct 952 ms 15648 KB Output is correct
5 Correct 957 ms 15512 KB Output is correct
6 Correct 958 ms 15564 KB Output is correct
7 Correct 960 ms 15580 KB Output is correct
8 Correct 963 ms 15568 KB Output is correct
9 Correct 965 ms 15636 KB Output is correct
10 Correct 956 ms 15588 KB Output is correct
11 Correct 956 ms 15564 KB Output is correct
12 Correct 952 ms 15552 KB Output is correct
13 Correct 960 ms 15640 KB Output is correct
14 Correct 962 ms 15568 KB Output is correct
15 Correct 962 ms 15568 KB Output is correct
16 Correct 961 ms 15560 KB Output is correct
17 Correct 955 ms 15572 KB Output is correct
18 Correct 953 ms 15560 KB Output is correct
19 Correct 962 ms 15556 KB Output is correct
20 Correct 957 ms 15640 KB Output is correct
21 Correct 955 ms 15608 KB Output is correct
22 Correct 959 ms 16712 KB Output is correct
23 Correct 989 ms 16692 KB Output is correct
24 Correct 971 ms 16708 KB Output is correct
25 Correct 970 ms 16696 KB Output is correct
26 Correct 966 ms 16696 KB Output is correct
27 Correct 1012 ms 16692 KB Output is correct
28 Correct 967 ms 16708 KB Output is correct
29 Correct 968 ms 16708 KB Output is correct
30 Correct 964 ms 16784 KB Output is correct
31 Correct 962 ms 16696 KB Output is correct
32 Correct 949 ms 16688 KB Output is correct
33 Correct 959 ms 16700 KB Output is correct
34 Correct 950 ms 16704 KB Output is correct
35 Correct 958 ms 16744 KB Output is correct
36 Correct 975 ms 16700 KB Output is correct
37 Correct 967 ms 16704 KB Output is correct
38 Correct 951 ms 16644 KB Output is correct
39 Correct 957 ms 16696 KB Output is correct
40 Correct 960 ms 16704 KB Output is correct
41 Correct 968 ms 16700 KB Output is correct
42 Correct 953 ms 16704 KB Output is correct
43 Correct 955 ms 16916 KB Output is correct
44 Correct 948 ms 16900 KB Output is correct
45 Correct 953 ms 16996 KB Output is correct
46 Correct 974 ms 16988 KB Output is correct
47 Correct 954 ms 16992 KB Output is correct
48 Correct 954 ms 16876 KB Output is correct
49 Correct 962 ms 16884 KB Output is correct
50 Correct 971 ms 16884 KB Output is correct
51 Correct 956 ms 17076 KB Output is correct
52 Correct 958 ms 16884 KB Output is correct
53 Correct 965 ms 17004 KB Output is correct
54 Correct 966 ms 17012 KB Output is correct
55 Correct 958 ms 16988 KB Output is correct
56 Correct 958 ms 17104 KB Output is correct
57 Correct 957 ms 17012 KB Output is correct
58 Correct 973 ms 17072 KB Output is correct
59 Correct 965 ms 16996 KB Output is correct
60 Correct 981 ms 16988 KB Output is correct
61 Correct 957 ms 16992 KB Output is correct
62 Correct 957 ms 16992 KB Output is correct
63 Correct 954 ms 16996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 967 ms 15568 KB Output is correct
2 Correct 966 ms 15568 KB Output is correct
3 Correct 953 ms 15640 KB Output is correct
4 Correct 952 ms 15648 KB Output is correct
5 Correct 957 ms 15512 KB Output is correct
6 Correct 958 ms 15564 KB Output is correct
7 Correct 960 ms 15580 KB Output is correct
8 Correct 963 ms 15568 KB Output is correct
9 Correct 965 ms 15636 KB Output is correct
10 Correct 956 ms 15588 KB Output is correct
11 Correct 956 ms 15564 KB Output is correct
12 Correct 952 ms 15552 KB Output is correct
13 Correct 960 ms 15640 KB Output is correct
14 Correct 962 ms 15568 KB Output is correct
15 Correct 962 ms 15568 KB Output is correct
16 Correct 961 ms 15560 KB Output is correct
17 Correct 955 ms 15572 KB Output is correct
18 Correct 953 ms 15560 KB Output is correct
19 Correct 962 ms 15556 KB Output is correct
20 Correct 957 ms 15640 KB Output is correct
21 Correct 955 ms 15608 KB Output is correct
22 Correct 959 ms 16712 KB Output is correct
23 Correct 989 ms 16692 KB Output is correct
24 Correct 971 ms 16708 KB Output is correct
25 Correct 970 ms 16696 KB Output is correct
26 Correct 966 ms 16696 KB Output is correct
27 Correct 1012 ms 16692 KB Output is correct
28 Correct 967 ms 16708 KB Output is correct
29 Correct 968 ms 16708 KB Output is correct
30 Correct 964 ms 16784 KB Output is correct
31 Correct 962 ms 16696 KB Output is correct
32 Correct 949 ms 16688 KB Output is correct
33 Correct 959 ms 16700 KB Output is correct
34 Correct 950 ms 16704 KB Output is correct
35 Correct 958 ms 16744 KB Output is correct
36 Correct 975 ms 16700 KB Output is correct
37 Correct 967 ms 16704 KB Output is correct
38 Correct 951 ms 16644 KB Output is correct
39 Correct 957 ms 16696 KB Output is correct
40 Correct 960 ms 16704 KB Output is correct
41 Correct 968 ms 16700 KB Output is correct
42 Correct 953 ms 16704 KB Output is correct
43 Correct 955 ms 16916 KB Output is correct
44 Correct 948 ms 16900 KB Output is correct
45 Correct 953 ms 16996 KB Output is correct
46 Correct 974 ms 16988 KB Output is correct
47 Correct 954 ms 16992 KB Output is correct
48 Correct 954 ms 16876 KB Output is correct
49 Correct 962 ms 16884 KB Output is correct
50 Correct 971 ms 16884 KB Output is correct
51 Correct 956 ms 17076 KB Output is correct
52 Correct 958 ms 16884 KB Output is correct
53 Correct 965 ms 17004 KB Output is correct
54 Correct 966 ms 17012 KB Output is correct
55 Correct 958 ms 16988 KB Output is correct
56 Correct 958 ms 17104 KB Output is correct
57 Correct 957 ms 17012 KB Output is correct
58 Correct 973 ms 17072 KB Output is correct
59 Correct 965 ms 16996 KB Output is correct
60 Correct 981 ms 16988 KB Output is correct
61 Correct 957 ms 16992 KB Output is correct
62 Correct 957 ms 16992 KB Output is correct
63 Correct 954 ms 16996 KB Output is correct
64 Correct 961 ms 17360 KB Output is correct
65 Correct 949 ms 17348 KB Output is correct
66 Correct 958 ms 17484 KB Output is correct
67 Correct 956 ms 17348 KB Output is correct
68 Correct 961 ms 17356 KB Output is correct
69 Correct 952 ms 17368 KB Output is correct
70 Correct 952 ms 17352 KB Output is correct
71 Correct 959 ms 17236 KB Output is correct
72 Correct 963 ms 17352 KB Output is correct
73 Correct 966 ms 17456 KB Output is correct
74 Correct 967 ms 17352 KB Output is correct
75 Correct 974 ms 17340 KB Output is correct
76 Correct 990 ms 17348 KB Output is correct
77 Correct 1014 ms 17344 KB Output is correct
78 Correct 998 ms 17256 KB Output is correct
79 Correct 1006 ms 17344 KB Output is correct
80 Correct 1024 ms 17356 KB Output is correct
81 Correct 974 ms 17352 KB Output is correct
82 Correct 1010 ms 17356 KB Output is correct
83 Correct 988 ms 17352 KB Output is correct
84 Correct 987 ms 17340 KB Output is correct