답안 #703136

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703136 2023-02-26T08:21:25 Z Cyanmond Cubeword (CEOI19_cubeword) C++17
84 / 100
1100 ms 138856 KB
#include <bits/stdc++.h>

using i64 = long long;
constexpr int L = 8;
constexpr i64 mod = 998244353;

/*
value of C
subtask 1 : 6
subtask 2 : 16
subtask 3 : 32
subtask 4 : 62
*/

int main() {
    int N;
    std::cin >> N;
    std::vector<std::string> words(N);
    for (auto &e : words) {
        std::cin >> e;
        auto b = e;
        std::reverse(b.begin(), b.end());
        if (e > b) {
            e = b;
        }
    }
    std::sort(words.begin(), words.end());
    words.erase(std::unique(words.begin(), words.end()), words.end());
    N = (int)words.size();

    std::vector<std::vector<int>> W(N);
    std::vector<char> chars;
    for (const auto &e : words) {
        for (const auto c : e) {
            chars.push_back(c);
        }
    }
    std::sort(chars.begin(), chars.end());
    chars.erase(std::unique(chars.begin(), chars.end()), chars.end());
    for (int i = 0; i < N; ++i) {
        for (const auto e : words[i]) {
            W[i].push_back((int)(std::lower_bound(chars.begin(), chars.end(), e) - chars.begin()));
        }
    }
    const int C = chars.size();
    std::array<std::vector<std::vector<i64>>, L> U;
    for (auto &vec : U) {
        vec.resize(C);
        for (auto &vec2 : vec) {
            vec2.assign(C, 0);
        }
    }
    for (int i = 0; i < N; ++i) {
        const int a = (int)W[i].size();
        ++U[a - 3][W[i][0]][W[i][a - 1]];
        auto w2 = W[i];
        std::reverse(w2.begin(), w2.end());
        if (W[i] != w2) {
            ++U[a - 3][w2[0]][w2[a - 1]];
        }
    }

    std::vector memo(C, std::vector(C, std::vector(C, std::vector(C, -1ll))));
    auto solve = [&](std::vector<std::vector<i64>> V) -> i64 {
        // C^8
        for (auto &vecss : memo) {
            for (auto &vecs : vecss) {
                for (auto &vec : vecs) {
                    std::fill(vec.begin(), vec.end(), -1);
                }
            }
        }

        std::vector mul(C, std::vector(C, std::vector(C, 0ll)));
        for (int a = 0; a < C; ++a) {
            for (int b = 0; b < C; ++b) {
                for (int c = 0; c < C; ++c) {
                    i64 s = 0;
                    for (int i = 0; i < C; ++i) {
                        i64 p = V[a][i] * V[b][i] * V[c][i];
                        s += p;
                        s %= mod;
                    }
                    mul[a][b][c] = s;
                }
            }
        }
        auto calc = [&](const std::array<int, 4> &cList) -> i64 {
            i64 ret = mul[cList[0]][cList[1]][cList[2]];
            ret *= mul[cList[0]][cList[1]][cList[3]];
            ret %= mod;
            ret *= mul[cList[0]][cList[2]][cList[3]];
            ret %= mod;
            ret *= mul[cList[1]][cList[2]][cList[3]];
            ret %= mod;
            return memo[cList[0]][cList[1]][cList[2]][cList[3]] = ret;
        };
        i64 res = 0;
        for (int a = 0; a < C; ++a) {
            for (int b = 0; b < C; ++b) {
                for (int c = 0; c < C; ++c) {
                    for (int d = 0; d < C; ++d) {
                        std::array<int, 4> list = {{a, b, c, d}};
                        std::sort(list.begin(), list.end());
                        if (memo[list[0]][list[1]][list[2]][list[3]] != -1) {
                            res += memo[list[0]][list[1]][list[2]][list[3]];
                        } else {
                            res += calc(list);
                        }
                        res %= mod;
                    }
                }
            }
        }
        return res;
    };
    i64 answer = 0;
    for (const auto &e : U) {
        answer += solve(e);
        answer %= mod;
    }
    std::cout << answer << std::endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 11896 KB Output is correct
2 Correct 132 ms 11860 KB Output is correct
3 Correct 130 ms 11936 KB Output is correct
4 Correct 106 ms 11832 KB Output is correct
5 Correct 106 ms 11852 KB Output is correct
6 Correct 104 ms 11868 KB Output is correct
7 Correct 115 ms 11840 KB Output is correct
8 Correct 105 ms 11872 KB Output is correct
9 Correct 106 ms 11868 KB Output is correct
10 Correct 106 ms 11872 KB Output is correct
11 Correct 113 ms 11860 KB Output is correct
12 Correct 108 ms 11840 KB Output is correct
13 Correct 108 ms 11844 KB Output is correct
14 Correct 103 ms 11852 KB Output is correct
15 Correct 113 ms 11844 KB Output is correct
16 Correct 109 ms 11872 KB Output is correct
17 Correct 106 ms 11860 KB Output is correct
18 Correct 107 ms 11824 KB Output is correct
19 Correct 106 ms 11880 KB Output is correct
20 Correct 110 ms 11856 KB Output is correct
21 Correct 106 ms 11864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 11896 KB Output is correct
2 Correct 132 ms 11860 KB Output is correct
3 Correct 130 ms 11936 KB Output is correct
4 Correct 106 ms 11832 KB Output is correct
5 Correct 106 ms 11852 KB Output is correct
6 Correct 104 ms 11868 KB Output is correct
7 Correct 115 ms 11840 KB Output is correct
8 Correct 105 ms 11872 KB Output is correct
9 Correct 106 ms 11868 KB Output is correct
10 Correct 106 ms 11872 KB Output is correct
11 Correct 113 ms 11860 KB Output is correct
12 Correct 108 ms 11840 KB Output is correct
13 Correct 108 ms 11844 KB Output is correct
14 Correct 103 ms 11852 KB Output is correct
15 Correct 113 ms 11844 KB Output is correct
16 Correct 109 ms 11872 KB Output is correct
17 Correct 106 ms 11860 KB Output is correct
18 Correct 107 ms 11824 KB Output is correct
19 Correct 106 ms 11880 KB Output is correct
20 Correct 110 ms 11856 KB Output is correct
21 Correct 106 ms 11864 KB Output is correct
22 Correct 120 ms 12252 KB Output is correct
23 Correct 122 ms 12236 KB Output is correct
24 Correct 121 ms 12240 KB Output is correct
25 Correct 125 ms 12292 KB Output is correct
26 Correct 120 ms 12216 KB Output is correct
27 Correct 119 ms 12248 KB Output is correct
28 Correct 121 ms 12372 KB Output is correct
29 Correct 123 ms 12244 KB Output is correct
30 Correct 122 ms 12256 KB Output is correct
31 Correct 124 ms 12240 KB Output is correct
32 Correct 121 ms 12244 KB Output is correct
33 Correct 125 ms 12240 KB Output is correct
34 Correct 127 ms 12224 KB Output is correct
35 Correct 119 ms 12252 KB Output is correct
36 Correct 119 ms 12312 KB Output is correct
37 Correct 137 ms 12244 KB Output is correct
38 Correct 121 ms 12224 KB Output is correct
39 Correct 121 ms 12244 KB Output is correct
40 Correct 123 ms 12348 KB Output is correct
41 Correct 123 ms 12256 KB Output is correct
42 Correct 136 ms 12240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 11896 KB Output is correct
2 Correct 132 ms 11860 KB Output is correct
3 Correct 130 ms 11936 KB Output is correct
4 Correct 106 ms 11832 KB Output is correct
5 Correct 106 ms 11852 KB Output is correct
6 Correct 104 ms 11868 KB Output is correct
7 Correct 115 ms 11840 KB Output is correct
8 Correct 105 ms 11872 KB Output is correct
9 Correct 106 ms 11868 KB Output is correct
10 Correct 106 ms 11872 KB Output is correct
11 Correct 113 ms 11860 KB Output is correct
12 Correct 108 ms 11840 KB Output is correct
13 Correct 108 ms 11844 KB Output is correct
14 Correct 103 ms 11852 KB Output is correct
15 Correct 113 ms 11844 KB Output is correct
16 Correct 109 ms 11872 KB Output is correct
17 Correct 106 ms 11860 KB Output is correct
18 Correct 107 ms 11824 KB Output is correct
19 Correct 106 ms 11880 KB Output is correct
20 Correct 110 ms 11856 KB Output is correct
21 Correct 106 ms 11864 KB Output is correct
22 Correct 120 ms 12252 KB Output is correct
23 Correct 122 ms 12236 KB Output is correct
24 Correct 121 ms 12240 KB Output is correct
25 Correct 125 ms 12292 KB Output is correct
26 Correct 120 ms 12216 KB Output is correct
27 Correct 119 ms 12248 KB Output is correct
28 Correct 121 ms 12372 KB Output is correct
29 Correct 123 ms 12244 KB Output is correct
30 Correct 122 ms 12256 KB Output is correct
31 Correct 124 ms 12240 KB Output is correct
32 Correct 121 ms 12244 KB Output is correct
33 Correct 125 ms 12240 KB Output is correct
34 Correct 127 ms 12224 KB Output is correct
35 Correct 119 ms 12252 KB Output is correct
36 Correct 119 ms 12312 KB Output is correct
37 Correct 137 ms 12244 KB Output is correct
38 Correct 121 ms 12224 KB Output is correct
39 Correct 121 ms 12244 KB Output is correct
40 Correct 123 ms 12348 KB Output is correct
41 Correct 123 ms 12256 KB Output is correct
42 Correct 136 ms 12240 KB Output is correct
43 Correct 338 ms 21444 KB Output is correct
44 Correct 339 ms 21424 KB Output is correct
45 Correct 334 ms 21380 KB Output is correct
46 Correct 336 ms 21384 KB Output is correct
47 Correct 333 ms 21368 KB Output is correct
48 Correct 332 ms 21372 KB Output is correct
49 Correct 331 ms 21376 KB Output is correct
50 Correct 334 ms 21464 KB Output is correct
51 Correct 371 ms 21376 KB Output is correct
52 Correct 327 ms 21468 KB Output is correct
53 Correct 359 ms 21472 KB Output is correct
54 Correct 323 ms 21332 KB Output is correct
55 Correct 333 ms 21312 KB Output is correct
56 Correct 330 ms 21332 KB Output is correct
57 Correct 336 ms 21368 KB Output is correct
58 Correct 337 ms 21376 KB Output is correct
59 Correct 353 ms 21372 KB Output is correct
60 Correct 325 ms 21460 KB Output is correct
61 Correct 344 ms 21468 KB Output is correct
62 Correct 325 ms 21344 KB Output is correct
63 Correct 357 ms 21372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 11896 KB Output is correct
2 Correct 132 ms 11860 KB Output is correct
3 Correct 130 ms 11936 KB Output is correct
4 Correct 106 ms 11832 KB Output is correct
5 Correct 106 ms 11852 KB Output is correct
6 Correct 104 ms 11868 KB Output is correct
7 Correct 115 ms 11840 KB Output is correct
8 Correct 105 ms 11872 KB Output is correct
9 Correct 106 ms 11868 KB Output is correct
10 Correct 106 ms 11872 KB Output is correct
11 Correct 113 ms 11860 KB Output is correct
12 Correct 108 ms 11840 KB Output is correct
13 Correct 108 ms 11844 KB Output is correct
14 Correct 103 ms 11852 KB Output is correct
15 Correct 113 ms 11844 KB Output is correct
16 Correct 109 ms 11872 KB Output is correct
17 Correct 106 ms 11860 KB Output is correct
18 Correct 107 ms 11824 KB Output is correct
19 Correct 106 ms 11880 KB Output is correct
20 Correct 110 ms 11856 KB Output is correct
21 Correct 106 ms 11864 KB Output is correct
22 Correct 120 ms 12252 KB Output is correct
23 Correct 122 ms 12236 KB Output is correct
24 Correct 121 ms 12240 KB Output is correct
25 Correct 125 ms 12292 KB Output is correct
26 Correct 120 ms 12216 KB Output is correct
27 Correct 119 ms 12248 KB Output is correct
28 Correct 121 ms 12372 KB Output is correct
29 Correct 123 ms 12244 KB Output is correct
30 Correct 122 ms 12256 KB Output is correct
31 Correct 124 ms 12240 KB Output is correct
32 Correct 121 ms 12244 KB Output is correct
33 Correct 125 ms 12240 KB Output is correct
34 Correct 127 ms 12224 KB Output is correct
35 Correct 119 ms 12252 KB Output is correct
36 Correct 119 ms 12312 KB Output is correct
37 Correct 137 ms 12244 KB Output is correct
38 Correct 121 ms 12224 KB Output is correct
39 Correct 121 ms 12244 KB Output is correct
40 Correct 123 ms 12348 KB Output is correct
41 Correct 123 ms 12256 KB Output is correct
42 Correct 136 ms 12240 KB Output is correct
43 Correct 338 ms 21444 KB Output is correct
44 Correct 339 ms 21424 KB Output is correct
45 Correct 334 ms 21380 KB Output is correct
46 Correct 336 ms 21384 KB Output is correct
47 Correct 333 ms 21368 KB Output is correct
48 Correct 332 ms 21372 KB Output is correct
49 Correct 331 ms 21376 KB Output is correct
50 Correct 334 ms 21464 KB Output is correct
51 Correct 371 ms 21376 KB Output is correct
52 Correct 327 ms 21468 KB Output is correct
53 Correct 359 ms 21472 KB Output is correct
54 Correct 323 ms 21332 KB Output is correct
55 Correct 333 ms 21312 KB Output is correct
56 Correct 330 ms 21332 KB Output is correct
57 Correct 336 ms 21368 KB Output is correct
58 Correct 337 ms 21376 KB Output is correct
59 Correct 353 ms 21372 KB Output is correct
60 Correct 325 ms 21460 KB Output is correct
61 Correct 344 ms 21468 KB Output is correct
62 Correct 325 ms 21344 KB Output is correct
63 Correct 357 ms 21372 KB Output is correct
64 Execution timed out 1176 ms 138856 KB Time limit exceeded
65 Halted 0 ms 0 KB -