Submission #779530

# Submission time Handle Problem Language Result Execution time Memory
779530 2023-07-11T13:53:12 Z ThegeekKnight16 Cubeword (CEOI19_cubeword) C++17
100 / 100
956 ms 35468 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 998244353;
const int MAXN = 72;
const int MAXT = 11;
//Freq of two ends of and edge
int freq[MAXT][MAXN][MAXN];
//Freq of the meeting of three edges
int freq3[MAXT][MAXN][MAXN][MAXN];
int letters[MAXT];
map<char, int> comp[MAXT];
set<string> palav[MAXT];
int resp = 0;
 
inline int add(int a, int b) {return (a + b) % MOD;}
inline int mult(int a, int b) {return (a * b) % MOD;}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        string s;
        cin >> s;
        palav[s.size()].insert(s);
        reverse(s.begin(), s.end());
        palav[s.size()].insert(s);
    }
 
    for (int i = 3; i < MAXT; i++)
    {
        for (auto &s : palav[i])
        {
            char b = s[0], f = s.back();
            if (comp[i][b] == 0) comp[i][b] = ++letters[i];
            if (comp[i][f] == 0) comp[i][f] = ++letters[i];
            freq[i][comp[i][b]][comp[i][f]]++;
        }
    }
 
    for (int t = 3; t < MAXT; t++)
    {
        for (int i = 1; i <= letters[t]; i++)
        {
            for (int j = i; j <= letters[t]; j++)
            {
                for (int k = j; k <= letters[t]; k++)
                {
                    for (int x = 1; x <= letters[t]; x++)
                    {
                        freq3[t][i][j][k] = freq3[t][i][k][j] = freq3[t][j][i][k] = freq3[t][j][k][i] = freq3[t][k][i][j] = freq3[t][k][j][i] = add(freq3[t][i][j][k], mult(freq[t][i][x], mult(freq[t][j][x], freq[t][k][x])));
                    }
                }
            }
        }
    }
 
    for (int t = 3; t < MAXT; t++)
    {
        for (int i = 1; i <= letters[t]; i++)
        {
            for (int j = 1; j <= letters[t]; j++)
            {
                for (int k = 1; k <= letters[t]; k++)
                {
                    int ansX = freq3[t][i][j][k];
                    if (ansX == 0) continue;
                    for (int l = 1; l <= letters[t]; l++)
                    {
                        int ans = ansX;
                        ans = mult(ans, freq3[t][i][j][l]);
                        ans = mult(ans, freq3[t][i][k][l]);
                        ans = mult(ans, freq3[t][j][k][l]);
                        resp = add(resp, ans);
                    }
                }
            }
        }
    }
 
    cout << resp << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 86 ms 15160 KB Output is correct
2 Correct 84 ms 15104 KB Output is correct
3 Correct 84 ms 15204 KB Output is correct
4 Correct 84 ms 15168 KB Output is correct
5 Correct 101 ms 15136 KB Output is correct
6 Correct 84 ms 15184 KB Output is correct
7 Correct 83 ms 15100 KB Output is correct
8 Correct 85 ms 15112 KB Output is correct
9 Correct 85 ms 15156 KB Output is correct
10 Correct 86 ms 15120 KB Output is correct
11 Correct 84 ms 15104 KB Output is correct
12 Correct 84 ms 15192 KB Output is correct
13 Correct 87 ms 15096 KB Output is correct
14 Correct 85 ms 15184 KB Output is correct
15 Correct 84 ms 15220 KB Output is correct
16 Correct 84 ms 15080 KB Output is correct
17 Correct 84 ms 15136 KB Output is correct
18 Correct 85 ms 15100 KB Output is correct
19 Correct 85 ms 15076 KB Output is correct
20 Correct 87 ms 15212 KB Output is correct
21 Correct 86 ms 15156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 15160 KB Output is correct
2 Correct 84 ms 15104 KB Output is correct
3 Correct 84 ms 15204 KB Output is correct
4 Correct 84 ms 15168 KB Output is correct
5 Correct 101 ms 15136 KB Output is correct
6 Correct 84 ms 15184 KB Output is correct
7 Correct 83 ms 15100 KB Output is correct
8 Correct 85 ms 15112 KB Output is correct
9 Correct 85 ms 15156 KB Output is correct
10 Correct 86 ms 15120 KB Output is correct
11 Correct 84 ms 15104 KB Output is correct
12 Correct 84 ms 15192 KB Output is correct
13 Correct 87 ms 15096 KB Output is correct
14 Correct 85 ms 15184 KB Output is correct
15 Correct 84 ms 15220 KB Output is correct
16 Correct 84 ms 15080 KB Output is correct
17 Correct 84 ms 15136 KB Output is correct
18 Correct 85 ms 15100 KB Output is correct
19 Correct 85 ms 15076 KB Output is correct
20 Correct 87 ms 15212 KB Output is correct
21 Correct 86 ms 15156 KB Output is correct
22 Correct 99 ms 17100 KB Output is correct
23 Correct 99 ms 17124 KB Output is correct
24 Correct 97 ms 17136 KB Output is correct
25 Correct 97 ms 17100 KB Output is correct
26 Correct 98 ms 17108 KB Output is correct
27 Correct 97 ms 17120 KB Output is correct
28 Correct 101 ms 17104 KB Output is correct
29 Correct 99 ms 17112 KB Output is correct
30 Correct 96 ms 17168 KB Output is correct
31 Correct 104 ms 17100 KB Output is correct
32 Correct 97 ms 17068 KB Output is correct
33 Correct 96 ms 17196 KB Output is correct
34 Correct 97 ms 17096 KB Output is correct
35 Correct 103 ms 17180 KB Output is correct
36 Correct 111 ms 17292 KB Output is correct
37 Correct 96 ms 17152 KB Output is correct
38 Correct 97 ms 17192 KB Output is correct
39 Correct 98 ms 17128 KB Output is correct
40 Correct 102 ms 17148 KB Output is correct
41 Correct 118 ms 17216 KB Output is correct
42 Correct 97 ms 17184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 15160 KB Output is correct
2 Correct 84 ms 15104 KB Output is correct
3 Correct 84 ms 15204 KB Output is correct
4 Correct 84 ms 15168 KB Output is correct
5 Correct 101 ms 15136 KB Output is correct
6 Correct 84 ms 15184 KB Output is correct
7 Correct 83 ms 15100 KB Output is correct
8 Correct 85 ms 15112 KB Output is correct
9 Correct 85 ms 15156 KB Output is correct
10 Correct 86 ms 15120 KB Output is correct
11 Correct 84 ms 15104 KB Output is correct
12 Correct 84 ms 15192 KB Output is correct
13 Correct 87 ms 15096 KB Output is correct
14 Correct 85 ms 15184 KB Output is correct
15 Correct 84 ms 15220 KB Output is correct
16 Correct 84 ms 15080 KB Output is correct
17 Correct 84 ms 15136 KB Output is correct
18 Correct 85 ms 15100 KB Output is correct
19 Correct 85 ms 15076 KB Output is correct
20 Correct 87 ms 15212 KB Output is correct
21 Correct 86 ms 15156 KB Output is correct
22 Correct 99 ms 17100 KB Output is correct
23 Correct 99 ms 17124 KB Output is correct
24 Correct 97 ms 17136 KB Output is correct
25 Correct 97 ms 17100 KB Output is correct
26 Correct 98 ms 17108 KB Output is correct
27 Correct 97 ms 17120 KB Output is correct
28 Correct 101 ms 17104 KB Output is correct
29 Correct 99 ms 17112 KB Output is correct
30 Correct 96 ms 17168 KB Output is correct
31 Correct 104 ms 17100 KB Output is correct
32 Correct 97 ms 17068 KB Output is correct
33 Correct 96 ms 17196 KB Output is correct
34 Correct 97 ms 17096 KB Output is correct
35 Correct 103 ms 17180 KB Output is correct
36 Correct 111 ms 17292 KB Output is correct
37 Correct 96 ms 17152 KB Output is correct
38 Correct 97 ms 17192 KB Output is correct
39 Correct 98 ms 17128 KB Output is correct
40 Correct 102 ms 17148 KB Output is correct
41 Correct 118 ms 17216 KB Output is correct
42 Correct 97 ms 17184 KB Output is correct
43 Correct 160 ms 21360 KB Output is correct
44 Correct 161 ms 21332 KB Output is correct
45 Correct 166 ms 21332 KB Output is correct
46 Correct 159 ms 21392 KB Output is correct
47 Correct 159 ms 21392 KB Output is correct
48 Correct 158 ms 21324 KB Output is correct
49 Correct 168 ms 21320 KB Output is correct
50 Correct 157 ms 21404 KB Output is correct
51 Correct 159 ms 21316 KB Output is correct
52 Correct 156 ms 21368 KB Output is correct
53 Correct 167 ms 21444 KB Output is correct
54 Correct 162 ms 21368 KB Output is correct
55 Correct 157 ms 21284 KB Output is correct
56 Correct 163 ms 21368 KB Output is correct
57 Correct 158 ms 21292 KB Output is correct
58 Correct 167 ms 21396 KB Output is correct
59 Correct 160 ms 21396 KB Output is correct
60 Correct 162 ms 21324 KB Output is correct
61 Correct 158 ms 21320 KB Output is correct
62 Correct 156 ms 21280 KB Output is correct
63 Correct 163 ms 21324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 15160 KB Output is correct
2 Correct 84 ms 15104 KB Output is correct
3 Correct 84 ms 15204 KB Output is correct
4 Correct 84 ms 15168 KB Output is correct
5 Correct 101 ms 15136 KB Output is correct
6 Correct 84 ms 15184 KB Output is correct
7 Correct 83 ms 15100 KB Output is correct
8 Correct 85 ms 15112 KB Output is correct
9 Correct 85 ms 15156 KB Output is correct
10 Correct 86 ms 15120 KB Output is correct
11 Correct 84 ms 15104 KB Output is correct
12 Correct 84 ms 15192 KB Output is correct
13 Correct 87 ms 15096 KB Output is correct
14 Correct 85 ms 15184 KB Output is correct
15 Correct 84 ms 15220 KB Output is correct
16 Correct 84 ms 15080 KB Output is correct
17 Correct 84 ms 15136 KB Output is correct
18 Correct 85 ms 15100 KB Output is correct
19 Correct 85 ms 15076 KB Output is correct
20 Correct 87 ms 15212 KB Output is correct
21 Correct 86 ms 15156 KB Output is correct
22 Correct 99 ms 17100 KB Output is correct
23 Correct 99 ms 17124 KB Output is correct
24 Correct 97 ms 17136 KB Output is correct
25 Correct 97 ms 17100 KB Output is correct
26 Correct 98 ms 17108 KB Output is correct
27 Correct 97 ms 17120 KB Output is correct
28 Correct 101 ms 17104 KB Output is correct
29 Correct 99 ms 17112 KB Output is correct
30 Correct 96 ms 17168 KB Output is correct
31 Correct 104 ms 17100 KB Output is correct
32 Correct 97 ms 17068 KB Output is correct
33 Correct 96 ms 17196 KB Output is correct
34 Correct 97 ms 17096 KB Output is correct
35 Correct 103 ms 17180 KB Output is correct
36 Correct 111 ms 17292 KB Output is correct
37 Correct 96 ms 17152 KB Output is correct
38 Correct 97 ms 17192 KB Output is correct
39 Correct 98 ms 17128 KB Output is correct
40 Correct 102 ms 17148 KB Output is correct
41 Correct 118 ms 17216 KB Output is correct
42 Correct 97 ms 17184 KB Output is correct
43 Correct 160 ms 21360 KB Output is correct
44 Correct 161 ms 21332 KB Output is correct
45 Correct 166 ms 21332 KB Output is correct
46 Correct 159 ms 21392 KB Output is correct
47 Correct 159 ms 21392 KB Output is correct
48 Correct 158 ms 21324 KB Output is correct
49 Correct 168 ms 21320 KB Output is correct
50 Correct 157 ms 21404 KB Output is correct
51 Correct 159 ms 21316 KB Output is correct
52 Correct 156 ms 21368 KB Output is correct
53 Correct 167 ms 21444 KB Output is correct
54 Correct 162 ms 21368 KB Output is correct
55 Correct 157 ms 21284 KB Output is correct
56 Correct 163 ms 21368 KB Output is correct
57 Correct 158 ms 21292 KB Output is correct
58 Correct 167 ms 21396 KB Output is correct
59 Correct 160 ms 21396 KB Output is correct
60 Correct 162 ms 21324 KB Output is correct
61 Correct 158 ms 21320 KB Output is correct
62 Correct 156 ms 21280 KB Output is correct
63 Correct 163 ms 21324 KB Output is correct
64 Correct 933 ms 35352 KB Output is correct
65 Correct 921 ms 35348 KB Output is correct
66 Correct 928 ms 35348 KB Output is correct
67 Correct 928 ms 35408 KB Output is correct
68 Correct 937 ms 35356 KB Output is correct
69 Correct 931 ms 35352 KB Output is correct
70 Correct 924 ms 35312 KB Output is correct
71 Correct 928 ms 35396 KB Output is correct
72 Correct 928 ms 35360 KB Output is correct
73 Correct 946 ms 35280 KB Output is correct
74 Correct 951 ms 35468 KB Output is correct
75 Correct 929 ms 35344 KB Output is correct
76 Correct 956 ms 35260 KB Output is correct
77 Correct 933 ms 35468 KB Output is correct
78 Correct 943 ms 35360 KB Output is correct
79 Correct 927 ms 35420 KB Output is correct
80 Correct 921 ms 35304 KB Output is correct
81 Correct 923 ms 35348 KB Output is correct
82 Correct 925 ms 35388 KB Output is correct
83 Correct 931 ms 35408 KB Output is correct
84 Correct 929 ms 35344 KB Output is correct