Submission #953614

# Submission time Handle Problem Language Result Execution time Memory
953614 2024-03-26T10:34:32 Z LucaIlie Cubeword (CEOI19_cubeword) C++17
84 / 100
1100 ms 16764 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() {
    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:50:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for ( int i = 0; i < t.size(); i++ )
      |                          ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 69 ms 13596 KB Output is correct
2 Correct 75 ms 13600 KB Output is correct
3 Correct 74 ms 13828 KB Output is correct
4 Correct 74 ms 13712 KB Output is correct
5 Correct 73 ms 13596 KB Output is correct
6 Correct 83 ms 13720 KB Output is correct
7 Correct 75 ms 13596 KB Output is correct
8 Correct 69 ms 13600 KB Output is correct
9 Correct 70 ms 13572 KB Output is correct
10 Correct 70 ms 13600 KB Output is correct
11 Correct 76 ms 13696 KB Output is correct
12 Correct 93 ms 13812 KB Output is correct
13 Correct 69 ms 13588 KB Output is correct
14 Correct 83 ms 13596 KB Output is correct
15 Correct 69 ms 13820 KB Output is correct
16 Correct 68 ms 13592 KB Output is correct
17 Correct 69 ms 13716 KB Output is correct
18 Correct 72 ms 13616 KB Output is correct
19 Correct 91 ms 13596 KB Output is correct
20 Correct 87 ms 13604 KB Output is correct
21 Correct 72 ms 13572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 13596 KB Output is correct
2 Correct 75 ms 13600 KB Output is correct
3 Correct 74 ms 13828 KB Output is correct
4 Correct 74 ms 13712 KB Output is correct
5 Correct 73 ms 13596 KB Output is correct
6 Correct 83 ms 13720 KB Output is correct
7 Correct 75 ms 13596 KB Output is correct
8 Correct 69 ms 13600 KB Output is correct
9 Correct 70 ms 13572 KB Output is correct
10 Correct 70 ms 13600 KB Output is correct
11 Correct 76 ms 13696 KB Output is correct
12 Correct 93 ms 13812 KB Output is correct
13 Correct 69 ms 13588 KB Output is correct
14 Correct 83 ms 13596 KB Output is correct
15 Correct 69 ms 13820 KB Output is correct
16 Correct 68 ms 13592 KB Output is correct
17 Correct 69 ms 13716 KB Output is correct
18 Correct 72 ms 13616 KB Output is correct
19 Correct 91 ms 13596 KB Output is correct
20 Correct 87 ms 13604 KB Output is correct
21 Correct 72 ms 13572 KB Output is correct
22 Correct 71 ms 15064 KB Output is correct
23 Correct 73 ms 15064 KB Output is correct
24 Correct 90 ms 14964 KB Output is correct
25 Correct 95 ms 14928 KB Output is correct
26 Correct 77 ms 14908 KB Output is correct
27 Correct 86 ms 15060 KB Output is correct
28 Correct 71 ms 15060 KB Output is correct
29 Correct 84 ms 15064 KB Output is correct
30 Correct 73 ms 14968 KB Output is correct
31 Correct 80 ms 14808 KB Output is correct
32 Correct 78 ms 14972 KB Output is correct
33 Correct 82 ms 14972 KB Output is correct
34 Correct 73 ms 14980 KB Output is correct
35 Correct 83 ms 15064 KB Output is correct
36 Correct 74 ms 14968 KB Output is correct
37 Correct 75 ms 14968 KB Output is correct
38 Correct 91 ms 15052 KB Output is correct
39 Correct 93 ms 14972 KB Output is correct
40 Correct 103 ms 14896 KB Output is correct
41 Correct 76 ms 14824 KB Output is correct
42 Correct 72 ms 15060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 13596 KB Output is correct
2 Correct 75 ms 13600 KB Output is correct
3 Correct 74 ms 13828 KB Output is correct
4 Correct 74 ms 13712 KB Output is correct
5 Correct 73 ms 13596 KB Output is correct
6 Correct 83 ms 13720 KB Output is correct
7 Correct 75 ms 13596 KB Output is correct
8 Correct 69 ms 13600 KB Output is correct
9 Correct 70 ms 13572 KB Output is correct
10 Correct 70 ms 13600 KB Output is correct
11 Correct 76 ms 13696 KB Output is correct
12 Correct 93 ms 13812 KB Output is correct
13 Correct 69 ms 13588 KB Output is correct
14 Correct 83 ms 13596 KB Output is correct
15 Correct 69 ms 13820 KB Output is correct
16 Correct 68 ms 13592 KB Output is correct
17 Correct 69 ms 13716 KB Output is correct
18 Correct 72 ms 13616 KB Output is correct
19 Correct 91 ms 13596 KB Output is correct
20 Correct 87 ms 13604 KB Output is correct
21 Correct 72 ms 13572 KB Output is correct
22 Correct 71 ms 15064 KB Output is correct
23 Correct 73 ms 15064 KB Output is correct
24 Correct 90 ms 14964 KB Output is correct
25 Correct 95 ms 14928 KB Output is correct
26 Correct 77 ms 14908 KB Output is correct
27 Correct 86 ms 15060 KB Output is correct
28 Correct 71 ms 15060 KB Output is correct
29 Correct 84 ms 15064 KB Output is correct
30 Correct 73 ms 14968 KB Output is correct
31 Correct 80 ms 14808 KB Output is correct
32 Correct 78 ms 14972 KB Output is correct
33 Correct 82 ms 14972 KB Output is correct
34 Correct 73 ms 14980 KB Output is correct
35 Correct 83 ms 15064 KB Output is correct
36 Correct 74 ms 14968 KB Output is correct
37 Correct 75 ms 14968 KB Output is correct
38 Correct 91 ms 15052 KB Output is correct
39 Correct 93 ms 14972 KB Output is correct
40 Correct 103 ms 14896 KB Output is correct
41 Correct 76 ms 14824 KB Output is correct
42 Correct 72 ms 15060 KB Output is correct
43 Correct 152 ms 15616 KB Output is correct
44 Correct 143 ms 15480 KB Output is correct
45 Correct 148 ms 15476 KB Output is correct
46 Correct 181 ms 15360 KB Output is correct
47 Correct 156 ms 15568 KB Output is correct
48 Correct 150 ms 15480 KB Output is correct
49 Correct 149 ms 15480 KB Output is correct
50 Correct 149 ms 15624 KB Output is correct
51 Correct 148 ms 15576 KB Output is correct
52 Correct 149 ms 15480 KB Output is correct
53 Correct 159 ms 15416 KB Output is correct
54 Correct 142 ms 15480 KB Output is correct
55 Correct 138 ms 15472 KB Output is correct
56 Correct 144 ms 15620 KB Output is correct
57 Correct 143 ms 15612 KB Output is correct
58 Correct 139 ms 15424 KB Output is correct
59 Correct 140 ms 15396 KB Output is correct
60 Correct 154 ms 15740 KB Output is correct
61 Correct 149 ms 15480 KB Output is correct
62 Correct 145 ms 15544 KB Output is correct
63 Correct 161 ms 15824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 13596 KB Output is correct
2 Correct 75 ms 13600 KB Output is correct
3 Correct 74 ms 13828 KB Output is correct
4 Correct 74 ms 13712 KB Output is correct
5 Correct 73 ms 13596 KB Output is correct
6 Correct 83 ms 13720 KB Output is correct
7 Correct 75 ms 13596 KB Output is correct
8 Correct 69 ms 13600 KB Output is correct
9 Correct 70 ms 13572 KB Output is correct
10 Correct 70 ms 13600 KB Output is correct
11 Correct 76 ms 13696 KB Output is correct
12 Correct 93 ms 13812 KB Output is correct
13 Correct 69 ms 13588 KB Output is correct
14 Correct 83 ms 13596 KB Output is correct
15 Correct 69 ms 13820 KB Output is correct
16 Correct 68 ms 13592 KB Output is correct
17 Correct 69 ms 13716 KB Output is correct
18 Correct 72 ms 13616 KB Output is correct
19 Correct 91 ms 13596 KB Output is correct
20 Correct 87 ms 13604 KB Output is correct
21 Correct 72 ms 13572 KB Output is correct
22 Correct 71 ms 15064 KB Output is correct
23 Correct 73 ms 15064 KB Output is correct
24 Correct 90 ms 14964 KB Output is correct
25 Correct 95 ms 14928 KB Output is correct
26 Correct 77 ms 14908 KB Output is correct
27 Correct 86 ms 15060 KB Output is correct
28 Correct 71 ms 15060 KB Output is correct
29 Correct 84 ms 15064 KB Output is correct
30 Correct 73 ms 14968 KB Output is correct
31 Correct 80 ms 14808 KB Output is correct
32 Correct 78 ms 14972 KB Output is correct
33 Correct 82 ms 14972 KB Output is correct
34 Correct 73 ms 14980 KB Output is correct
35 Correct 83 ms 15064 KB Output is correct
36 Correct 74 ms 14968 KB Output is correct
37 Correct 75 ms 14968 KB Output is correct
38 Correct 91 ms 15052 KB Output is correct
39 Correct 93 ms 14972 KB Output is correct
40 Correct 103 ms 14896 KB Output is correct
41 Correct 76 ms 14824 KB Output is correct
42 Correct 72 ms 15060 KB Output is correct
43 Correct 152 ms 15616 KB Output is correct
44 Correct 143 ms 15480 KB Output is correct
45 Correct 148 ms 15476 KB Output is correct
46 Correct 181 ms 15360 KB Output is correct
47 Correct 156 ms 15568 KB Output is correct
48 Correct 150 ms 15480 KB Output is correct
49 Correct 149 ms 15480 KB Output is correct
50 Correct 149 ms 15624 KB Output is correct
51 Correct 148 ms 15576 KB Output is correct
52 Correct 149 ms 15480 KB Output is correct
53 Correct 159 ms 15416 KB Output is correct
54 Correct 142 ms 15480 KB Output is correct
55 Correct 138 ms 15472 KB Output is correct
56 Correct 144 ms 15620 KB Output is correct
57 Correct 143 ms 15612 KB Output is correct
58 Correct 139 ms 15424 KB Output is correct
59 Correct 140 ms 15396 KB Output is correct
60 Correct 154 ms 15740 KB Output is correct
61 Correct 149 ms 15480 KB Output is correct
62 Correct 145 ms 15544 KB Output is correct
63 Correct 161 ms 15824 KB Output is correct
64 Correct 1081 ms 16604 KB Output is correct
65 Correct 1064 ms 16520 KB Output is correct
66 Correct 1080 ms 16524 KB Output is correct
67 Correct 1087 ms 16520 KB Output is correct
68 Correct 1074 ms 16516 KB Output is correct
69 Correct 1096 ms 16516 KB Output is correct
70 Correct 1097 ms 16684 KB Output is correct
71 Correct 1071 ms 16532 KB Output is correct
72 Correct 1078 ms 16520 KB Output is correct
73 Correct 1089 ms 16528 KB Output is correct
74 Correct 1070 ms 16520 KB Output is correct
75 Correct 1067 ms 16436 KB Output is correct
76 Correct 1071 ms 16592 KB Output is correct
77 Correct 1073 ms 16684 KB Output is correct
78 Correct 1085 ms 16528 KB Output is correct
79 Correct 1092 ms 16692 KB Output is correct
80 Correct 1068 ms 16764 KB Output is correct
81 Correct 1100 ms 16520 KB Output is correct
82 Correct 1080 ms 16516 KB Output is correct
83 Execution timed out 1109 ms 16736 KB Time limit exceeded
84 Halted 0 ms 0 KB -