Submission #533184

# Submission time Handle Problem Language Result Execution time Memory
533184 2022-03-05T05:10:23 Z wenqi Cubeword (CEOI19_cubeword) C++17
84 / 100
1100 ms 23092 KB
// trans rights

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define MOD 998244353
#define H 62

int N;
unordered_set<string> problems[11][H];
int pre[11][H][H];
int cnt[11][H][H][H];
int mapping[256];

bool is_palindrome(const string& word)
{
    return equal(word.begin(), word.end(), word.rbegin());
}

uint64_t reduce(uint64_t a) {
    return a - (uint64_t)((__uint128_t(-1ULL / MOD) * a) >> 64) * MOD;
}

ll mul(ll x, ll y)
{
    return reduce(x * y);
    return ((__int128_t) x * (__int128_t) y) >> 64;
}

template <typename ...Args>
ll mul(ll x, ll y, Args&&... args)
{
    return mul(mul(x, y), forward<Args>(args)...);
}

int main(int argc, const char *argv[])
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    for (int x = 'a'; x <= 'z'; x++)
    {
        mapping[x] = x - 'a';
    }
    for (int x = 'A'; x <= 'Z'; x++)
    {
        mapping[x] = x - 'A' + 26;
    }
    for (int x = '0'; x <= '9'; x++)
    {
        mapping[x] = x - '0' + 52;
    }
    cin >> N;
    for (int k = 0; k < N; k++)
    {
        string word;
        cin >> word;
        problems[word.size()][mapping[word[0]]].insert(word);

        reverse(word.begin(), word.end());
        problems[word.size()][mapping[word[0]]].insert(word);
    }
    int ans = 0;

    for (int sz = 1; sz <= 10; sz++)
    {
        for (int start = 0; start < H; start++)
        {
            for (auto &word : problems[sz][start])
            {
                pre[sz][start][mapping[word.back()]]++;
            }
        }
    }

    for (int sz = 1; sz <= 10; sz++)
    {
        for (int start = 0; start < H; start++)
        {
            auto &A = pre[sz][start];
            for (int x = 0; x < H; x++)
            {
                if (A[x] == 0)
                    continue;

                for (int y = 0; y < H; y++)
                {
                    if (A[y] == 0)
                        continue;

                    for (int z = 0; z < H; z++)
                    {
                        cnt[sz][x][y][z] += mul(A[x], A[y], A[z]);
                        cnt[sz][x][y][z] %= MOD;
                    }
                }
            }
        }
    }

    for (int sz = 1; sz <= 10; sz++)
    {
        for (int x = 0; x < H; x++)
        {
            for (int y = 0; y < H; y++)
            {
                for (int z = 0; z < H; z++)
                {
                    if (cnt[sz][x][y][z] == 0)
                        continue;

                    for (int w = 0; w < H; w++)
                    {
                        ans += mul(cnt[sz][x][y][z], cnt[sz][x][y][w], cnt[sz][x][w][z], cnt[sz][y][z][w]);
                        ans %= MOD;
                    }
                }
            }
        }
    }

    cout << ans;
    return 0;
}

Compilation message

cubeword.cpp: In function 'int main(int, const char**)':
cubeword.cpp:59:46: warning: array subscript has type 'char' [-Wchar-subscripts]
   59 |         problems[word.size()][mapping[word[0]]].insert(word);
      |                                              ^
cubeword.cpp:62:46: warning: array subscript has type 'char' [-Wchar-subscripts]
   62 |         problems[word.size()][mapping[word[0]]].insert(word);
      |                                              ^
cubeword.cpp:72:49: warning: array subscript has type 'char' [-Wchar-subscripts]
   72 |                 pre[sz][start][mapping[word.back()]]++;
      |                                        ~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 86 ms 14700 KB Output is correct
2 Correct 91 ms 15044 KB Output is correct
3 Correct 90 ms 14928 KB Output is correct
4 Correct 97 ms 15020 KB Output is correct
5 Correct 95 ms 14936 KB Output is correct
6 Correct 89 ms 14976 KB Output is correct
7 Correct 91 ms 15048 KB Output is correct
8 Correct 90 ms 15060 KB Output is correct
9 Correct 92 ms 15112 KB Output is correct
10 Correct 101 ms 15056 KB Output is correct
11 Correct 90 ms 15116 KB Output is correct
12 Correct 85 ms 14940 KB Output is correct
13 Correct 88 ms 15044 KB Output is correct
14 Correct 97 ms 15044 KB Output is correct
15 Correct 89 ms 15020 KB Output is correct
16 Correct 90 ms 14988 KB Output is correct
17 Correct 93 ms 15052 KB Output is correct
18 Correct 92 ms 14984 KB Output is correct
19 Correct 93 ms 15172 KB Output is correct
20 Correct 92 ms 15004 KB Output is correct
21 Correct 86 ms 15072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 14700 KB Output is correct
2 Correct 91 ms 15044 KB Output is correct
3 Correct 90 ms 14928 KB Output is correct
4 Correct 97 ms 15020 KB Output is correct
5 Correct 95 ms 14936 KB Output is correct
6 Correct 89 ms 14976 KB Output is correct
7 Correct 91 ms 15048 KB Output is correct
8 Correct 90 ms 15060 KB Output is correct
9 Correct 92 ms 15112 KB Output is correct
10 Correct 101 ms 15056 KB Output is correct
11 Correct 90 ms 15116 KB Output is correct
12 Correct 85 ms 14940 KB Output is correct
13 Correct 88 ms 15044 KB Output is correct
14 Correct 97 ms 15044 KB Output is correct
15 Correct 89 ms 15020 KB Output is correct
16 Correct 90 ms 14988 KB Output is correct
17 Correct 93 ms 15052 KB Output is correct
18 Correct 92 ms 14984 KB Output is correct
19 Correct 93 ms 15172 KB Output is correct
20 Correct 92 ms 15004 KB Output is correct
21 Correct 86 ms 15072 KB Output is correct
22 Correct 120 ms 16184 KB Output is correct
23 Correct 110 ms 16132 KB Output is correct
24 Correct 112 ms 16288 KB Output is correct
25 Correct 115 ms 16160 KB Output is correct
26 Correct 112 ms 16168 KB Output is correct
27 Correct 110 ms 16184 KB Output is correct
28 Correct 108 ms 16196 KB Output is correct
29 Correct 111 ms 16148 KB Output is correct
30 Correct 106 ms 16068 KB Output is correct
31 Correct 112 ms 16188 KB Output is correct
32 Correct 109 ms 16064 KB Output is correct
33 Correct 129 ms 16108 KB Output is correct
34 Correct 116 ms 16068 KB Output is correct
35 Correct 110 ms 16140 KB Output is correct
36 Correct 114 ms 16200 KB Output is correct
37 Correct 117 ms 16272 KB Output is correct
38 Correct 108 ms 16108 KB Output is correct
39 Correct 108 ms 16192 KB Output is correct
40 Correct 127 ms 16196 KB Output is correct
41 Correct 112 ms 16160 KB Output is correct
42 Correct 120 ms 16344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 14700 KB Output is correct
2 Correct 91 ms 15044 KB Output is correct
3 Correct 90 ms 14928 KB Output is correct
4 Correct 97 ms 15020 KB Output is correct
5 Correct 95 ms 14936 KB Output is correct
6 Correct 89 ms 14976 KB Output is correct
7 Correct 91 ms 15048 KB Output is correct
8 Correct 90 ms 15060 KB Output is correct
9 Correct 92 ms 15112 KB Output is correct
10 Correct 101 ms 15056 KB Output is correct
11 Correct 90 ms 15116 KB Output is correct
12 Correct 85 ms 14940 KB Output is correct
13 Correct 88 ms 15044 KB Output is correct
14 Correct 97 ms 15044 KB Output is correct
15 Correct 89 ms 15020 KB Output is correct
16 Correct 90 ms 14988 KB Output is correct
17 Correct 93 ms 15052 KB Output is correct
18 Correct 92 ms 14984 KB Output is correct
19 Correct 93 ms 15172 KB Output is correct
20 Correct 92 ms 15004 KB Output is correct
21 Correct 86 ms 15072 KB Output is correct
22 Correct 120 ms 16184 KB Output is correct
23 Correct 110 ms 16132 KB Output is correct
24 Correct 112 ms 16288 KB Output is correct
25 Correct 115 ms 16160 KB Output is correct
26 Correct 112 ms 16168 KB Output is correct
27 Correct 110 ms 16184 KB Output is correct
28 Correct 108 ms 16196 KB Output is correct
29 Correct 111 ms 16148 KB Output is correct
30 Correct 106 ms 16068 KB Output is correct
31 Correct 112 ms 16188 KB Output is correct
32 Correct 109 ms 16064 KB Output is correct
33 Correct 129 ms 16108 KB Output is correct
34 Correct 116 ms 16068 KB Output is correct
35 Correct 110 ms 16140 KB Output is correct
36 Correct 114 ms 16200 KB Output is correct
37 Correct 117 ms 16272 KB Output is correct
38 Correct 108 ms 16108 KB Output is correct
39 Correct 108 ms 16192 KB Output is correct
40 Correct 127 ms 16196 KB Output is correct
41 Correct 112 ms 16160 KB Output is correct
42 Correct 120 ms 16344 KB Output is correct
43 Correct 226 ms 19092 KB Output is correct
44 Correct 240 ms 19100 KB Output is correct
45 Correct 234 ms 19204 KB Output is correct
46 Correct 228 ms 19076 KB Output is correct
47 Correct 242 ms 19096 KB Output is correct
48 Correct 241 ms 19144 KB Output is correct
49 Correct 236 ms 19052 KB Output is correct
50 Correct 227 ms 19140 KB Output is correct
51 Correct 234 ms 19232 KB Output is correct
52 Correct 228 ms 19004 KB Output is correct
53 Correct 234 ms 19012 KB Output is correct
54 Correct 238 ms 19076 KB Output is correct
55 Correct 227 ms 19076 KB Output is correct
56 Correct 235 ms 19016 KB Output is correct
57 Correct 238 ms 19104 KB Output is correct
58 Correct 230 ms 19004 KB Output is correct
59 Correct 238 ms 19052 KB Output is correct
60 Correct 245 ms 19128 KB Output is correct
61 Correct 233 ms 19040 KB Output is correct
62 Correct 230 ms 19084 KB Output is correct
63 Correct 235 ms 19140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 14700 KB Output is correct
2 Correct 91 ms 15044 KB Output is correct
3 Correct 90 ms 14928 KB Output is correct
4 Correct 97 ms 15020 KB Output is correct
5 Correct 95 ms 14936 KB Output is correct
6 Correct 89 ms 14976 KB Output is correct
7 Correct 91 ms 15048 KB Output is correct
8 Correct 90 ms 15060 KB Output is correct
9 Correct 92 ms 15112 KB Output is correct
10 Correct 101 ms 15056 KB Output is correct
11 Correct 90 ms 15116 KB Output is correct
12 Correct 85 ms 14940 KB Output is correct
13 Correct 88 ms 15044 KB Output is correct
14 Correct 97 ms 15044 KB Output is correct
15 Correct 89 ms 15020 KB Output is correct
16 Correct 90 ms 14988 KB Output is correct
17 Correct 93 ms 15052 KB Output is correct
18 Correct 92 ms 14984 KB Output is correct
19 Correct 93 ms 15172 KB Output is correct
20 Correct 92 ms 15004 KB Output is correct
21 Correct 86 ms 15072 KB Output is correct
22 Correct 120 ms 16184 KB Output is correct
23 Correct 110 ms 16132 KB Output is correct
24 Correct 112 ms 16288 KB Output is correct
25 Correct 115 ms 16160 KB Output is correct
26 Correct 112 ms 16168 KB Output is correct
27 Correct 110 ms 16184 KB Output is correct
28 Correct 108 ms 16196 KB Output is correct
29 Correct 111 ms 16148 KB Output is correct
30 Correct 106 ms 16068 KB Output is correct
31 Correct 112 ms 16188 KB Output is correct
32 Correct 109 ms 16064 KB Output is correct
33 Correct 129 ms 16108 KB Output is correct
34 Correct 116 ms 16068 KB Output is correct
35 Correct 110 ms 16140 KB Output is correct
36 Correct 114 ms 16200 KB Output is correct
37 Correct 117 ms 16272 KB Output is correct
38 Correct 108 ms 16108 KB Output is correct
39 Correct 108 ms 16192 KB Output is correct
40 Correct 127 ms 16196 KB Output is correct
41 Correct 112 ms 16160 KB Output is correct
42 Correct 120 ms 16344 KB Output is correct
43 Correct 226 ms 19092 KB Output is correct
44 Correct 240 ms 19100 KB Output is correct
45 Correct 234 ms 19204 KB Output is correct
46 Correct 228 ms 19076 KB Output is correct
47 Correct 242 ms 19096 KB Output is correct
48 Correct 241 ms 19144 KB Output is correct
49 Correct 236 ms 19052 KB Output is correct
50 Correct 227 ms 19140 KB Output is correct
51 Correct 234 ms 19232 KB Output is correct
52 Correct 228 ms 19004 KB Output is correct
53 Correct 234 ms 19012 KB Output is correct
54 Correct 238 ms 19076 KB Output is correct
55 Correct 227 ms 19076 KB Output is correct
56 Correct 235 ms 19016 KB Output is correct
57 Correct 238 ms 19104 KB Output is correct
58 Correct 230 ms 19004 KB Output is correct
59 Correct 238 ms 19052 KB Output is correct
60 Correct 245 ms 19128 KB Output is correct
61 Correct 233 ms 19040 KB Output is correct
62 Correct 230 ms 19084 KB Output is correct
63 Correct 235 ms 19140 KB Output is correct
64 Execution timed out 1117 ms 23092 KB Time limit exceeded
65 Halted 0 ms 0 KB -