답안 #572382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572382 2022-06-04T10:12:07 Z piOOE Cubeword (CEOI19_cubeword) C++17
84 / 100
752 ms 15312 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;

typedef long long ll;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }

const int N = 8, A = 32, L = 11, mod = 998244353;
const ll infL = 3e18;

int g[N][3] = {{1, 2, 4},
               {0, 3, 5},
               {0, 3, 6},
               {1, 2, 7},
               {0, 5, 6},
               {1, 4, 7},
               {2, 4, 7},
               {3, 5, 6}};

int n;
int cnt[A][A][L], used[N], dp2[A][A][A], dp7[A][A][A], dp1[A][A][A], dp4[A][A][A];
int ans = 0, len = 0;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    vector<string> stt;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        string ss = s;
        reverse(all(ss));
        stt.push_back(ss);
        stt.push_back(s);
    }
    sort(all(stt));
    stt.resize(unique(all(stt)) - begin(stt));
    for (string s: stt) {
        ++cnt[islower(s[0]) ? int(s[0] - 'a') : s[0] - 'A' + 16][islower(s.back()) ? int(s.back() - 'a') : s.back() -
                                                                                                           'A' + 16][sz(
                s)];
    }
    for (len = 1; len < L; ++len) {
        {
            //2
            memset(used, -1, sizeof(used));
            for (int x0 = 0; x0 < A; ++x0) {
                used[0] = x0;
                for (int x3 = 0; x3 < A; ++x3) {
                    used[3] = x3;
                    for (int x6 = 0; x6 < A; ++x6) {
                        used[6] = x6;
                        int sum = 0;
                        for (int x = 0; x < A; ++x) {
                            int now = 1;
                            for (int to: g[2]) {
                                assert(used[to] != -1);
                                now = (now * (ll) cnt[x][used[to]][len]) % mod;
                            }
                            sum = (sum + now) % mod;
                        }
                        dp2[x0][x3][x6] = sum;
                    }
                }
            }
        }
        {
            //1
            memset(used, -1, sizeof(used));
            for (int x0 = 0; x0 < A; ++x0) {
                used[0] = x0;
                for (int x3 = 0; x3 < A; ++x3) {
                    used[3] = x3;
                    for (int x5 = 0; x5 < A; ++x5) {
                        used[5] = x5;
                        int sum = 0;
                        for (int x = 0; x < A; ++x) {
                            int now = 1;
                            for (int to: g[1]) {
                                assert(used[to] != -1);
                                now = (now * (ll) cnt[x][used[to]][len]) % mod;
                            }
                            sum = (sum + now) % mod;
                        }
                        dp1[x0][x3][x5] = sum;
                    }
                }
            }
        }
        {
            //7
            memset(used, -1, sizeof(used));
            for (int x6 = 0; x6 < A; ++x6) {
                used[6] = x6;
                for (int x3 = 0; x3 < A; ++x3) {
                    used[3] = x3;
                    for (int x5 = 0; x5 < A; ++x5) {
                        used[5] = x5;
                        int sum = 0;
                        for (int x = 0; x < A; ++x) {
                            int now = 1;
                            for (int to: g[7]) {
                                assert(used[to] != -1);
                                now = (now * (ll) cnt[x][used[to]][len]) % mod;
                            }
                            sum = (sum + now) % mod;
                        }
                        dp7[x3][x5][x6] = sum;
                    }
                }
            }
        }
        {
            //4
            memset(used, -1, sizeof(used));
            for (int x0 = 0; x0 < A; ++x0) {
                used[0] = x0;
                for (int x6 = 0; x6 < A; ++x6) {
                    used[6] = x6;
                    for (int x5 = 0; x5 < A; ++x5) {
                        used[5] = x5;
                        int sum = 0;
                        for (int x = 0; x < A; ++x) {
                            int now = 1;
                            for (int to: g[4]) {
                                assert(used[to] != -1);
                                now = (now * (ll) cnt[x][used[to]][len]) % mod;
                            }
                            sum = (sum + now) % mod;
                        }
                        dp4[x0][x5][x6] = sum;
                    }
                }
            }
        }
        for (int x0 = 0; x0 < A; ++x0) {
            for (int x3 = 0; x3 < A; ++x3) {
                for (int x5 = 0; x5 < A; ++x5) {
                    for (int x6 = 0; x6 < A; ++x6) {
                        ans = (ans + dp4[x0][x5][x6] * (ll) dp7[x3][x5][x6] % mod * (ll) dp1[x0][x3][x5] % mod *
                                     (ll) dp2[x0][x3][x6]) % mod;
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 752 ms 8648 KB Output is correct
2 Correct 727 ms 8776 KB Output is correct
3 Correct 715 ms 8776 KB Output is correct
4 Correct 731 ms 8776 KB Output is correct
5 Correct 742 ms 8784 KB Output is correct
6 Correct 714 ms 8776 KB Output is correct
7 Correct 714 ms 8728 KB Output is correct
8 Correct 718 ms 8780 KB Output is correct
9 Correct 717 ms 8776 KB Output is correct
10 Correct 724 ms 8776 KB Output is correct
11 Correct 748 ms 8776 KB Output is correct
12 Correct 736 ms 8772 KB Output is correct
13 Correct 719 ms 8776 KB Output is correct
14 Correct 730 ms 8772 KB Output is correct
15 Correct 732 ms 8776 KB Output is correct
16 Correct 722 ms 8688 KB Output is correct
17 Correct 709 ms 8776 KB Output is correct
18 Correct 729 ms 8828 KB Output is correct
19 Correct 719 ms 8776 KB Output is correct
20 Correct 718 ms 8776 KB Output is correct
21 Correct 723 ms 8776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 752 ms 8648 KB Output is correct
2 Correct 727 ms 8776 KB Output is correct
3 Correct 715 ms 8776 KB Output is correct
4 Correct 731 ms 8776 KB Output is correct
5 Correct 742 ms 8784 KB Output is correct
6 Correct 714 ms 8776 KB Output is correct
7 Correct 714 ms 8728 KB Output is correct
8 Correct 718 ms 8780 KB Output is correct
9 Correct 717 ms 8776 KB Output is correct
10 Correct 724 ms 8776 KB Output is correct
11 Correct 748 ms 8776 KB Output is correct
12 Correct 736 ms 8772 KB Output is correct
13 Correct 719 ms 8776 KB Output is correct
14 Correct 730 ms 8772 KB Output is correct
15 Correct 732 ms 8776 KB Output is correct
16 Correct 722 ms 8688 KB Output is correct
17 Correct 709 ms 8776 KB Output is correct
18 Correct 729 ms 8828 KB Output is correct
19 Correct 719 ms 8776 KB Output is correct
20 Correct 718 ms 8776 KB Output is correct
21 Correct 723 ms 8776 KB Output is correct
22 Correct 720 ms 8780 KB Output is correct
23 Correct 702 ms 9408 KB Output is correct
24 Correct 708 ms 9380 KB Output is correct
25 Correct 698 ms 9416 KB Output is correct
26 Correct 714 ms 9408 KB Output is correct
27 Correct 737 ms 9408 KB Output is correct
28 Correct 705 ms 9416 KB Output is correct
29 Correct 705 ms 9416 KB Output is correct
30 Correct 710 ms 8648 KB Output is correct
31 Correct 698 ms 8640 KB Output is correct
32 Correct 717 ms 8640 KB Output is correct
33 Correct 713 ms 8584 KB Output is correct
34 Correct 718 ms 8648 KB Output is correct
35 Correct 722 ms 8648 KB Output is correct
36 Correct 748 ms 8592 KB Output is correct
37 Correct 742 ms 8680 KB Output is correct
38 Correct 700 ms 8648 KB Output is correct
39 Correct 705 ms 8648 KB Output is correct
40 Correct 727 ms 8648 KB Output is correct
41 Correct 731 ms 8636 KB Output is correct
42 Correct 727 ms 8648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 752 ms 8648 KB Output is correct
2 Correct 727 ms 8776 KB Output is correct
3 Correct 715 ms 8776 KB Output is correct
4 Correct 731 ms 8776 KB Output is correct
5 Correct 742 ms 8784 KB Output is correct
6 Correct 714 ms 8776 KB Output is correct
7 Correct 714 ms 8728 KB Output is correct
8 Correct 718 ms 8780 KB Output is correct
9 Correct 717 ms 8776 KB Output is correct
10 Correct 724 ms 8776 KB Output is correct
11 Correct 748 ms 8776 KB Output is correct
12 Correct 736 ms 8772 KB Output is correct
13 Correct 719 ms 8776 KB Output is correct
14 Correct 730 ms 8772 KB Output is correct
15 Correct 732 ms 8776 KB Output is correct
16 Correct 722 ms 8688 KB Output is correct
17 Correct 709 ms 8776 KB Output is correct
18 Correct 729 ms 8828 KB Output is correct
19 Correct 719 ms 8776 KB Output is correct
20 Correct 718 ms 8776 KB Output is correct
21 Correct 723 ms 8776 KB Output is correct
22 Correct 720 ms 8780 KB Output is correct
23 Correct 702 ms 9408 KB Output is correct
24 Correct 708 ms 9380 KB Output is correct
25 Correct 698 ms 9416 KB Output is correct
26 Correct 714 ms 9408 KB Output is correct
27 Correct 737 ms 9408 KB Output is correct
28 Correct 705 ms 9416 KB Output is correct
29 Correct 705 ms 9416 KB Output is correct
30 Correct 710 ms 8648 KB Output is correct
31 Correct 698 ms 8640 KB Output is correct
32 Correct 717 ms 8640 KB Output is correct
33 Correct 713 ms 8584 KB Output is correct
34 Correct 718 ms 8648 KB Output is correct
35 Correct 722 ms 8648 KB Output is correct
36 Correct 748 ms 8592 KB Output is correct
37 Correct 742 ms 8680 KB Output is correct
38 Correct 700 ms 8648 KB Output is correct
39 Correct 705 ms 8648 KB Output is correct
40 Correct 727 ms 8648 KB Output is correct
41 Correct 731 ms 8636 KB Output is correct
42 Correct 727 ms 8648 KB Output is correct
43 Correct 694 ms 8612 KB Output is correct
44 Correct 723 ms 9288 KB Output is correct
45 Correct 709 ms 9288 KB Output is correct
46 Correct 691 ms 9276 KB Output is correct
47 Correct 696 ms 9288 KB Output is correct
48 Correct 707 ms 9288 KB Output is correct
49 Correct 718 ms 9288 KB Output is correct
50 Correct 699 ms 9272 KB Output is correct
51 Correct 726 ms 9288 KB Output is correct
52 Correct 707 ms 9288 KB Output is correct
53 Correct 702 ms 9288 KB Output is correct
54 Correct 697 ms 9288 KB Output is correct
55 Correct 717 ms 9216 KB Output is correct
56 Correct 698 ms 9288 KB Output is correct
57 Correct 698 ms 9308 KB Output is correct
58 Correct 711 ms 9288 KB Output is correct
59 Correct 739 ms 9288 KB Output is correct
60 Correct 701 ms 9288 KB Output is correct
61 Correct 707 ms 9344 KB Output is correct
62 Correct 722 ms 9300 KB Output is correct
63 Correct 703 ms 9288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 752 ms 8648 KB Output is correct
2 Correct 727 ms 8776 KB Output is correct
3 Correct 715 ms 8776 KB Output is correct
4 Correct 731 ms 8776 KB Output is correct
5 Correct 742 ms 8784 KB Output is correct
6 Correct 714 ms 8776 KB Output is correct
7 Correct 714 ms 8728 KB Output is correct
8 Correct 718 ms 8780 KB Output is correct
9 Correct 717 ms 8776 KB Output is correct
10 Correct 724 ms 8776 KB Output is correct
11 Correct 748 ms 8776 KB Output is correct
12 Correct 736 ms 8772 KB Output is correct
13 Correct 719 ms 8776 KB Output is correct
14 Correct 730 ms 8772 KB Output is correct
15 Correct 732 ms 8776 KB Output is correct
16 Correct 722 ms 8688 KB Output is correct
17 Correct 709 ms 8776 KB Output is correct
18 Correct 729 ms 8828 KB Output is correct
19 Correct 719 ms 8776 KB Output is correct
20 Correct 718 ms 8776 KB Output is correct
21 Correct 723 ms 8776 KB Output is correct
22 Correct 720 ms 8780 KB Output is correct
23 Correct 702 ms 9408 KB Output is correct
24 Correct 708 ms 9380 KB Output is correct
25 Correct 698 ms 9416 KB Output is correct
26 Correct 714 ms 9408 KB Output is correct
27 Correct 737 ms 9408 KB Output is correct
28 Correct 705 ms 9416 KB Output is correct
29 Correct 705 ms 9416 KB Output is correct
30 Correct 710 ms 8648 KB Output is correct
31 Correct 698 ms 8640 KB Output is correct
32 Correct 717 ms 8640 KB Output is correct
33 Correct 713 ms 8584 KB Output is correct
34 Correct 718 ms 8648 KB Output is correct
35 Correct 722 ms 8648 KB Output is correct
36 Correct 748 ms 8592 KB Output is correct
37 Correct 742 ms 8680 KB Output is correct
38 Correct 700 ms 8648 KB Output is correct
39 Correct 705 ms 8648 KB Output is correct
40 Correct 727 ms 8648 KB Output is correct
41 Correct 731 ms 8636 KB Output is correct
42 Correct 727 ms 8648 KB Output is correct
43 Correct 694 ms 8612 KB Output is correct
44 Correct 723 ms 9288 KB Output is correct
45 Correct 709 ms 9288 KB Output is correct
46 Correct 691 ms 9276 KB Output is correct
47 Correct 696 ms 9288 KB Output is correct
48 Correct 707 ms 9288 KB Output is correct
49 Correct 718 ms 9288 KB Output is correct
50 Correct 699 ms 9272 KB Output is correct
51 Correct 726 ms 9288 KB Output is correct
52 Correct 707 ms 9288 KB Output is correct
53 Correct 702 ms 9288 KB Output is correct
54 Correct 697 ms 9288 KB Output is correct
55 Correct 717 ms 9216 KB Output is correct
56 Correct 698 ms 9288 KB Output is correct
57 Correct 698 ms 9308 KB Output is correct
58 Correct 711 ms 9288 KB Output is correct
59 Correct 739 ms 9288 KB Output is correct
60 Correct 701 ms 9288 KB Output is correct
61 Correct 707 ms 9344 KB Output is correct
62 Correct 722 ms 9300 KB Output is correct
63 Correct 703 ms 9288 KB Output is correct
64 Runtime error 712 ms 15312 KB Execution killed with signal 11
65 Halted 0 ms 0 KB -