답안 #953615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
953615 2024-03-26T10:37:03 Z LucaIlie Cubeword (CEOI19_cubeword) C++17
84 / 100
1100 ms 16552 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_ID = 62;
const int MIN_LEN = 3;
const int MAX_LEN = 10;
const int MOD = 998244353;
unordered_set<string> s[MAX_LEN + 1];
unordered_map<char, int> id;
int m;
int coef[MAX_ID][MAX_ID], prod[MAX_ID][MAX_ID][MAX_ID];

int solve() {
    int ans = 0;

    for ( int a = 0; a < m; a++ ) {
        for ( int b = 0; b < m; b++ ) {
            for ( int c = 0; c < m; c++ ) {
                prod[a][b][c] = 0;
                for ( int i = 0; i < m; i++ )
                    prod[a][b][c] = (prod[a][b][c] + (long long)coef[a][i] * coef[b][i] % MOD * coef[c][i]) % MOD;
            }
        }
    }


    for ( int a = 0; a < m; a++ ) {
        for ( int b = 0; b < m; b++ ) {
            for ( int c = 0; c < m; c++ ) {
                for ( int d = 0; d < m; d++ )
                    ans = (ans + prod[a][b][c] * (long long)prod[a][b][d] % MOD * prod[a][c][d] % MOD * prod[b][c][d]) % MOD;
            }
        }
    }

    return ans;
}

int main() {
    cin.tie( NULL );
    ios_base::sync_with_stdio( false );
    
    int n;

    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        string t;
        cin >> t;
        s[t.size()].insert( t );
        reverse( t.begin(), t.end() );
        s[t.size()].insert( t );
        for ( int i = 0; i < t.size(); i++ )
            id[t[i]] = 1;
    }

    m = 0;
    for ( auto p: id )
        id[p.first] = m++;

    int ans = 0;
    for ( int l = MIN_LEN; l <= MAX_LEN; l++ ) {
        if ( s[l].size() == 0 )
            continue;

        for ( int i = 0; i < m; i++ ) {
            for ( int j = 0; j < m; j++ )
                coef[i][j] = 0;
        }
        for ( string t: s[l] )
            coef[id[t[0]]][id[t.back()]]++;

        ans = (ans + solve()) % MOD;
    }

    cout << ans;

    return 0;
}

Compilation message

cubeword.cpp: In function 'int main()':
cubeword.cpp:53:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for ( int i = 0; i < t.size(); i++ )
      |                          ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 13600 KB Output is correct
2 Correct 56 ms 13596 KB Output is correct
3 Correct 55 ms 13828 KB Output is correct
4 Correct 57 ms 13604 KB Output is correct
5 Correct 62 ms 13852 KB Output is correct
6 Correct 54 ms 13768 KB Output is correct
7 Correct 56 ms 13852 KB Output is correct
8 Correct 85 ms 13732 KB Output is correct
9 Correct 67 ms 13596 KB Output is correct
10 Correct 54 ms 13616 KB Output is correct
11 Correct 68 ms 13596 KB Output is correct
12 Correct 68 ms 13600 KB Output is correct
13 Correct 77 ms 13704 KB Output is correct
14 Correct 60 ms 13592 KB Output is correct
15 Correct 56 ms 13756 KB Output is correct
16 Correct 57 ms 13596 KB Output is correct
17 Correct 72 ms 13864 KB Output is correct
18 Correct 71 ms 13856 KB Output is correct
19 Correct 55 ms 13600 KB Output is correct
20 Correct 68 ms 13600 KB Output is correct
21 Correct 78 ms 13592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 13600 KB Output is correct
2 Correct 56 ms 13596 KB Output is correct
3 Correct 55 ms 13828 KB Output is correct
4 Correct 57 ms 13604 KB Output is correct
5 Correct 62 ms 13852 KB Output is correct
6 Correct 54 ms 13768 KB Output is correct
7 Correct 56 ms 13852 KB Output is correct
8 Correct 85 ms 13732 KB Output is correct
9 Correct 67 ms 13596 KB Output is correct
10 Correct 54 ms 13616 KB Output is correct
11 Correct 68 ms 13596 KB Output is correct
12 Correct 68 ms 13600 KB Output is correct
13 Correct 77 ms 13704 KB Output is correct
14 Correct 60 ms 13592 KB Output is correct
15 Correct 56 ms 13756 KB Output is correct
16 Correct 57 ms 13596 KB Output is correct
17 Correct 72 ms 13864 KB Output is correct
18 Correct 71 ms 13856 KB Output is correct
19 Correct 55 ms 13600 KB Output is correct
20 Correct 68 ms 13600 KB Output is correct
21 Correct 78 ms 13592 KB Output is correct
22 Correct 60 ms 14936 KB Output is correct
23 Correct 63 ms 15064 KB Output is correct
24 Correct 60 ms 14872 KB Output is correct
25 Correct 61 ms 15068 KB Output is correct
26 Correct 77 ms 15072 KB Output is correct
27 Correct 63 ms 15080 KB Output is correct
28 Correct 67 ms 14848 KB Output is correct
29 Correct 60 ms 15060 KB Output is correct
30 Correct 68 ms 14944 KB Output is correct
31 Correct 61 ms 15060 KB Output is correct
32 Correct 75 ms 14968 KB Output is correct
33 Correct 73 ms 15080 KB Output is correct
34 Correct 56 ms 15060 KB Output is correct
35 Correct 59 ms 14952 KB Output is correct
36 Correct 58 ms 14968 KB Output is correct
37 Correct 71 ms 14844 KB Output is correct
38 Correct 58 ms 14972 KB Output is correct
39 Correct 68 ms 14932 KB Output is correct
40 Correct 60 ms 15060 KB Output is correct
41 Correct 58 ms 14840 KB Output is correct
42 Correct 64 ms 15064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 13600 KB Output is correct
2 Correct 56 ms 13596 KB Output is correct
3 Correct 55 ms 13828 KB Output is correct
4 Correct 57 ms 13604 KB Output is correct
5 Correct 62 ms 13852 KB Output is correct
6 Correct 54 ms 13768 KB Output is correct
7 Correct 56 ms 13852 KB Output is correct
8 Correct 85 ms 13732 KB Output is correct
9 Correct 67 ms 13596 KB Output is correct
10 Correct 54 ms 13616 KB Output is correct
11 Correct 68 ms 13596 KB Output is correct
12 Correct 68 ms 13600 KB Output is correct
13 Correct 77 ms 13704 KB Output is correct
14 Correct 60 ms 13592 KB Output is correct
15 Correct 56 ms 13756 KB Output is correct
16 Correct 57 ms 13596 KB Output is correct
17 Correct 72 ms 13864 KB Output is correct
18 Correct 71 ms 13856 KB Output is correct
19 Correct 55 ms 13600 KB Output is correct
20 Correct 68 ms 13600 KB Output is correct
21 Correct 78 ms 13592 KB Output is correct
22 Correct 60 ms 14936 KB Output is correct
23 Correct 63 ms 15064 KB Output is correct
24 Correct 60 ms 14872 KB Output is correct
25 Correct 61 ms 15068 KB Output is correct
26 Correct 77 ms 15072 KB Output is correct
27 Correct 63 ms 15080 KB Output is correct
28 Correct 67 ms 14848 KB Output is correct
29 Correct 60 ms 15060 KB Output is correct
30 Correct 68 ms 14944 KB Output is correct
31 Correct 61 ms 15060 KB Output is correct
32 Correct 75 ms 14968 KB Output is correct
33 Correct 73 ms 15080 KB Output is correct
34 Correct 56 ms 15060 KB Output is correct
35 Correct 59 ms 14952 KB Output is correct
36 Correct 58 ms 14968 KB Output is correct
37 Correct 71 ms 14844 KB Output is correct
38 Correct 58 ms 14972 KB Output is correct
39 Correct 68 ms 14932 KB Output is correct
40 Correct 60 ms 15060 KB Output is correct
41 Correct 58 ms 14840 KB Output is correct
42 Correct 64 ms 15064 KB Output is correct
43 Correct 148 ms 15884 KB Output is correct
44 Correct 151 ms 15480 KB Output is correct
45 Correct 132 ms 15488 KB Output is correct
46 Correct 147 ms 15412 KB Output is correct
47 Correct 151 ms 15828 KB Output is correct
48 Correct 134 ms 15484 KB Output is correct
49 Correct 136 ms 15480 KB Output is correct
50 Correct 130 ms 15656 KB Output is correct
51 Correct 152 ms 15636 KB Output is correct
52 Correct 130 ms 15400 KB Output is correct
53 Correct 140 ms 15480 KB Output is correct
54 Correct 127 ms 15484 KB Output is correct
55 Correct 124 ms 15484 KB Output is correct
56 Correct 139 ms 15636 KB Output is correct
57 Correct 156 ms 15632 KB Output is correct
58 Correct 161 ms 15644 KB Output is correct
59 Correct 134 ms 15688 KB Output is correct
60 Correct 128 ms 15484 KB Output is correct
61 Correct 126 ms 15552 KB Output is correct
62 Correct 124 ms 15548 KB Output is correct
63 Correct 126 ms 15648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 13600 KB Output is correct
2 Correct 56 ms 13596 KB Output is correct
3 Correct 55 ms 13828 KB Output is correct
4 Correct 57 ms 13604 KB Output is correct
5 Correct 62 ms 13852 KB Output is correct
6 Correct 54 ms 13768 KB Output is correct
7 Correct 56 ms 13852 KB Output is correct
8 Correct 85 ms 13732 KB Output is correct
9 Correct 67 ms 13596 KB Output is correct
10 Correct 54 ms 13616 KB Output is correct
11 Correct 68 ms 13596 KB Output is correct
12 Correct 68 ms 13600 KB Output is correct
13 Correct 77 ms 13704 KB Output is correct
14 Correct 60 ms 13592 KB Output is correct
15 Correct 56 ms 13756 KB Output is correct
16 Correct 57 ms 13596 KB Output is correct
17 Correct 72 ms 13864 KB Output is correct
18 Correct 71 ms 13856 KB Output is correct
19 Correct 55 ms 13600 KB Output is correct
20 Correct 68 ms 13600 KB Output is correct
21 Correct 78 ms 13592 KB Output is correct
22 Correct 60 ms 14936 KB Output is correct
23 Correct 63 ms 15064 KB Output is correct
24 Correct 60 ms 14872 KB Output is correct
25 Correct 61 ms 15068 KB Output is correct
26 Correct 77 ms 15072 KB Output is correct
27 Correct 63 ms 15080 KB Output is correct
28 Correct 67 ms 14848 KB Output is correct
29 Correct 60 ms 15060 KB Output is correct
30 Correct 68 ms 14944 KB Output is correct
31 Correct 61 ms 15060 KB Output is correct
32 Correct 75 ms 14968 KB Output is correct
33 Correct 73 ms 15080 KB Output is correct
34 Correct 56 ms 15060 KB Output is correct
35 Correct 59 ms 14952 KB Output is correct
36 Correct 58 ms 14968 KB Output is correct
37 Correct 71 ms 14844 KB Output is correct
38 Correct 58 ms 14972 KB Output is correct
39 Correct 68 ms 14932 KB Output is correct
40 Correct 60 ms 15060 KB Output is correct
41 Correct 58 ms 14840 KB Output is correct
42 Correct 64 ms 15064 KB Output is correct
43 Correct 148 ms 15884 KB Output is correct
44 Correct 151 ms 15480 KB Output is correct
45 Correct 132 ms 15488 KB Output is correct
46 Correct 147 ms 15412 KB Output is correct
47 Correct 151 ms 15828 KB Output is correct
48 Correct 134 ms 15484 KB Output is correct
49 Correct 136 ms 15480 KB Output is correct
50 Correct 130 ms 15656 KB Output is correct
51 Correct 152 ms 15636 KB Output is correct
52 Correct 130 ms 15400 KB Output is correct
53 Correct 140 ms 15480 KB Output is correct
54 Correct 127 ms 15484 KB Output is correct
55 Correct 124 ms 15484 KB Output is correct
56 Correct 139 ms 15636 KB Output is correct
57 Correct 156 ms 15632 KB Output is correct
58 Correct 161 ms 15644 KB Output is correct
59 Correct 134 ms 15688 KB Output is correct
60 Correct 128 ms 15484 KB Output is correct
61 Correct 126 ms 15552 KB Output is correct
62 Correct 124 ms 15548 KB Output is correct
63 Correct 126 ms 15648 KB Output is correct
64 Correct 1065 ms 16548 KB Output is correct
65 Correct 1068 ms 16548 KB Output is correct
66 Correct 1089 ms 16480 KB Output is correct
67 Correct 1094 ms 16548 KB Output is correct
68 Execution timed out 1115 ms 16552 KB Time limit exceeded
69 Halted 0 ms 0 KB -