답안 #519046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519046 2022-01-25T13:06:08 Z Monarchuwu Cubeword (CEOI19_cubeword) C++17
84 / 100
1100 ms 11440 KB
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<unordered_set>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;

const int N = 1e5 + 9, mod = 998244353;
int n;
int a[11][62][62][2];

bool palind(string s) {
    int l(0), r(s.size() - 1);
    while (l < r) {
        if (s[l] != s[r]) return false;
        ++l, --r;
    }
    return true;
}

int num(char c) {
    if ('a' <= c && c <= 'z') return c - 'a';
    if ('A' <= c && c <= 'Z') return c - 'A' + 26;
    if ('0' <= c && c <= '9') return c - '0' + 52;
    return -1;
}

ll calc(int len, int i, int j) {
    if (i != j) {
        if (i > j) swap(i, j);
        return a[len][i][j][0];
    }
    return (a[len][i][j][1] + a[len][i][j][0] * 2) % mod;
}

ll d[62][62][62];
void build_d(int len) {
    for (int i1 = 0; i1 < n; ++i1)
        for (int i2 = 0; i2 < n; ++i2)
            for (int i3 = 0; i3 < n; ++i3) {
                d[i1][i2][i3] = 0;
                for (int i = 0; i < n; ++i)
                    (d[i1][i2][i3] += calc(len, i, i1) * calc(len, i, i2) % mod * calc(len, i, i3)) %= mod;
            }
}

int main() {
    cin.tie(NULL)->sync_with_stdio(false);
    cin >> n;

    unordered_set<string> S;
    vector<int> ch;
    for (int ii = 0; ii < n; ++ii) {
        string s; cin >> s;
        if (S.count(s)) continue;

        int i = num(s[0]), j = num(s.back());
        if (i > j) swap(i, j);
        ch.push_back(i);
        ch.push_back(j);

        ++a[s.size()][i][j][palind(s)];
        reverse(all(s));
        S.insert(s);
    }
    sort(all(ch));
    ch.resize(unique(all(ch)) - ch.begin());
    n = ch.size();

    for (int len = 3; len <= 10; ++len)
        for (int i = 0; i < n; ++i)
            for (int j = i; j < n; ++j) {
                int i1 = ch[i], i2 = ch[j];
                a[len][i][j][0] = a[len][i1][i2][0];
                a[len][i][j][1] = a[len][i1][i2][1];
            }

    ll ans(0);
    for (int len = 3; len <= 10; ++len) {
        build_d(len);
        for (int i1 = 0; i1 < n; ++i1)
            for (int i2 = 0; i2 < n; ++i2)
                for (int i3 = 0; i3 < n; ++i3)
                    for (int i4 = 0; i4 < n; ++i4)
                        (ans += d[i1][i2][i3] * d[i1][i2][i4] % mod * d[i1][i3][i4] % mod * d[i2][i3][i4]) %= mod;
    }
    cout << ans << '\n';
}
/**  /\_/\
 *  (= ._.)
 *  / >0  \>1
**/
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 9144 KB Output is correct
2 Correct 47 ms 9240 KB Output is correct
3 Correct 50 ms 9148 KB Output is correct
4 Correct 45 ms 9228 KB Output is correct
5 Correct 45 ms 9160 KB Output is correct
6 Correct 51 ms 9172 KB Output is correct
7 Correct 44 ms 9156 KB Output is correct
8 Correct 47 ms 9172 KB Output is correct
9 Correct 48 ms 9240 KB Output is correct
10 Correct 49 ms 9160 KB Output is correct
11 Correct 48 ms 9164 KB Output is correct
12 Correct 53 ms 9244 KB Output is correct
13 Correct 53 ms 9380 KB Output is correct
14 Correct 49 ms 9168 KB Output is correct
15 Correct 44 ms 9168 KB Output is correct
16 Correct 45 ms 9160 KB Output is correct
17 Correct 46 ms 9212 KB Output is correct
18 Correct 48 ms 9196 KB Output is correct
19 Correct 52 ms 9224 KB Output is correct
20 Correct 61 ms 9240 KB Output is correct
21 Correct 50 ms 9248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 9144 KB Output is correct
2 Correct 47 ms 9240 KB Output is correct
3 Correct 50 ms 9148 KB Output is correct
4 Correct 45 ms 9228 KB Output is correct
5 Correct 45 ms 9160 KB Output is correct
6 Correct 51 ms 9172 KB Output is correct
7 Correct 44 ms 9156 KB Output is correct
8 Correct 47 ms 9172 KB Output is correct
9 Correct 48 ms 9240 KB Output is correct
10 Correct 49 ms 9160 KB Output is correct
11 Correct 48 ms 9164 KB Output is correct
12 Correct 53 ms 9244 KB Output is correct
13 Correct 53 ms 9380 KB Output is correct
14 Correct 49 ms 9168 KB Output is correct
15 Correct 44 ms 9168 KB Output is correct
16 Correct 45 ms 9160 KB Output is correct
17 Correct 46 ms 9212 KB Output is correct
18 Correct 48 ms 9196 KB Output is correct
19 Correct 52 ms 9224 KB Output is correct
20 Correct 61 ms 9240 KB Output is correct
21 Correct 50 ms 9248 KB Output is correct
22 Correct 54 ms 9492 KB Output is correct
23 Correct 52 ms 9484 KB Output is correct
24 Correct 64 ms 9448 KB Output is correct
25 Correct 54 ms 9520 KB Output is correct
26 Correct 55 ms 9448 KB Output is correct
27 Correct 53 ms 9520 KB Output is correct
28 Correct 56 ms 9516 KB Output is correct
29 Correct 52 ms 9512 KB Output is correct
30 Correct 52 ms 9500 KB Output is correct
31 Correct 54 ms 9516 KB Output is correct
32 Correct 53 ms 9492 KB Output is correct
33 Correct 54 ms 9520 KB Output is correct
34 Correct 53 ms 9520 KB Output is correct
35 Correct 54 ms 9488 KB Output is correct
36 Correct 51 ms 9520 KB Output is correct
37 Correct 51 ms 9520 KB Output is correct
38 Correct 56 ms 9504 KB Output is correct
39 Correct 55 ms 9504 KB Output is correct
40 Correct 51 ms 9456 KB Output is correct
41 Correct 56 ms 9516 KB Output is correct
42 Correct 52 ms 9520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 9144 KB Output is correct
2 Correct 47 ms 9240 KB Output is correct
3 Correct 50 ms 9148 KB Output is correct
4 Correct 45 ms 9228 KB Output is correct
5 Correct 45 ms 9160 KB Output is correct
6 Correct 51 ms 9172 KB Output is correct
7 Correct 44 ms 9156 KB Output is correct
8 Correct 47 ms 9172 KB Output is correct
9 Correct 48 ms 9240 KB Output is correct
10 Correct 49 ms 9160 KB Output is correct
11 Correct 48 ms 9164 KB Output is correct
12 Correct 53 ms 9244 KB Output is correct
13 Correct 53 ms 9380 KB Output is correct
14 Correct 49 ms 9168 KB Output is correct
15 Correct 44 ms 9168 KB Output is correct
16 Correct 45 ms 9160 KB Output is correct
17 Correct 46 ms 9212 KB Output is correct
18 Correct 48 ms 9196 KB Output is correct
19 Correct 52 ms 9224 KB Output is correct
20 Correct 61 ms 9240 KB Output is correct
21 Correct 50 ms 9248 KB Output is correct
22 Correct 54 ms 9492 KB Output is correct
23 Correct 52 ms 9484 KB Output is correct
24 Correct 64 ms 9448 KB Output is correct
25 Correct 54 ms 9520 KB Output is correct
26 Correct 55 ms 9448 KB Output is correct
27 Correct 53 ms 9520 KB Output is correct
28 Correct 56 ms 9516 KB Output is correct
29 Correct 52 ms 9512 KB Output is correct
30 Correct 52 ms 9500 KB Output is correct
31 Correct 54 ms 9516 KB Output is correct
32 Correct 53 ms 9492 KB Output is correct
33 Correct 54 ms 9520 KB Output is correct
34 Correct 53 ms 9520 KB Output is correct
35 Correct 54 ms 9488 KB Output is correct
36 Correct 51 ms 9520 KB Output is correct
37 Correct 51 ms 9520 KB Output is correct
38 Correct 56 ms 9504 KB Output is correct
39 Correct 55 ms 9504 KB Output is correct
40 Correct 51 ms 9456 KB Output is correct
41 Correct 56 ms 9516 KB Output is correct
42 Correct 52 ms 9520 KB Output is correct
43 Correct 147 ms 10156 KB Output is correct
44 Correct 145 ms 10104 KB Output is correct
45 Correct 141 ms 10032 KB Output is correct
46 Correct 164 ms 10136 KB Output is correct
47 Correct 139 ms 10024 KB Output is correct
48 Correct 143 ms 10024 KB Output is correct
49 Correct 148 ms 10032 KB Output is correct
50 Correct 140 ms 10160 KB Output is correct
51 Correct 168 ms 10132 KB Output is correct
52 Correct 148 ms 10108 KB Output is correct
53 Correct 148 ms 10064 KB Output is correct
54 Correct 143 ms 10048 KB Output is correct
55 Correct 142 ms 10132 KB Output is correct
56 Correct 149 ms 10032 KB Output is correct
57 Correct 146 ms 10132 KB Output is correct
58 Correct 166 ms 10136 KB Output is correct
59 Correct 141 ms 10072 KB Output is correct
60 Correct 145 ms 10040 KB Output is correct
61 Correct 150 ms 10024 KB Output is correct
62 Correct 149 ms 10108 KB Output is correct
63 Correct 146 ms 10164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 9144 KB Output is correct
2 Correct 47 ms 9240 KB Output is correct
3 Correct 50 ms 9148 KB Output is correct
4 Correct 45 ms 9228 KB Output is correct
5 Correct 45 ms 9160 KB Output is correct
6 Correct 51 ms 9172 KB Output is correct
7 Correct 44 ms 9156 KB Output is correct
8 Correct 47 ms 9172 KB Output is correct
9 Correct 48 ms 9240 KB Output is correct
10 Correct 49 ms 9160 KB Output is correct
11 Correct 48 ms 9164 KB Output is correct
12 Correct 53 ms 9244 KB Output is correct
13 Correct 53 ms 9380 KB Output is correct
14 Correct 49 ms 9168 KB Output is correct
15 Correct 44 ms 9168 KB Output is correct
16 Correct 45 ms 9160 KB Output is correct
17 Correct 46 ms 9212 KB Output is correct
18 Correct 48 ms 9196 KB Output is correct
19 Correct 52 ms 9224 KB Output is correct
20 Correct 61 ms 9240 KB Output is correct
21 Correct 50 ms 9248 KB Output is correct
22 Correct 54 ms 9492 KB Output is correct
23 Correct 52 ms 9484 KB Output is correct
24 Correct 64 ms 9448 KB Output is correct
25 Correct 54 ms 9520 KB Output is correct
26 Correct 55 ms 9448 KB Output is correct
27 Correct 53 ms 9520 KB Output is correct
28 Correct 56 ms 9516 KB Output is correct
29 Correct 52 ms 9512 KB Output is correct
30 Correct 52 ms 9500 KB Output is correct
31 Correct 54 ms 9516 KB Output is correct
32 Correct 53 ms 9492 KB Output is correct
33 Correct 54 ms 9520 KB Output is correct
34 Correct 53 ms 9520 KB Output is correct
35 Correct 54 ms 9488 KB Output is correct
36 Correct 51 ms 9520 KB Output is correct
37 Correct 51 ms 9520 KB Output is correct
38 Correct 56 ms 9504 KB Output is correct
39 Correct 55 ms 9504 KB Output is correct
40 Correct 51 ms 9456 KB Output is correct
41 Correct 56 ms 9516 KB Output is correct
42 Correct 52 ms 9520 KB Output is correct
43 Correct 147 ms 10156 KB Output is correct
44 Correct 145 ms 10104 KB Output is correct
45 Correct 141 ms 10032 KB Output is correct
46 Correct 164 ms 10136 KB Output is correct
47 Correct 139 ms 10024 KB Output is correct
48 Correct 143 ms 10024 KB Output is correct
49 Correct 148 ms 10032 KB Output is correct
50 Correct 140 ms 10160 KB Output is correct
51 Correct 168 ms 10132 KB Output is correct
52 Correct 148 ms 10108 KB Output is correct
53 Correct 148 ms 10064 KB Output is correct
54 Correct 143 ms 10048 KB Output is correct
55 Correct 142 ms 10132 KB Output is correct
56 Correct 149 ms 10032 KB Output is correct
57 Correct 146 ms 10132 KB Output is correct
58 Correct 166 ms 10136 KB Output is correct
59 Correct 141 ms 10072 KB Output is correct
60 Correct 145 ms 10040 KB Output is correct
61 Correct 150 ms 10024 KB Output is correct
62 Correct 149 ms 10108 KB Output is correct
63 Correct 146 ms 10164 KB Output is correct
64 Execution timed out 1204 ms 11440 KB Time limit exceeded
65 Halted 0 ms 0 KB -