Submission #446280

# Submission time Handle Problem Language Result Execution time Memory
446280 2021-07-21T12:52:50 Z benedict0724 Cubeword (CEOI19_cubeword) C++17
100 / 100
432 ms 27076 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll cnt[62][62][11];
ll Pre[62][62][62][11];
ll ans = 0;
const ll mod = 998244353;
map<string, int> M;

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

int main()
{
    int n; cin >> n;
    for(int i=1;i<=n;i++)
    {
        string s; cin >> s;

        string p = s;
        reverse(p.begin(), p.end());
        if(M[p]) continue;

        M[s] = 1;
        int t = s.size();
        int a = f(s[0]);
        int b = f(s[t-1]);
        bool flag = true;
        for(int i=0;i<t;i++)
        {
            if(s[i] != s[t-i-1]) flag = false;
        }

        if(a != b) { cnt[a][b][t]++; cnt[b][a][t]++; }
        else if(flag) cnt[a][a][t]++;
        else cnt[a][a][t] += 2;
    }

    for(int t=3;t<=10;t++)
    {
        for(int i=0;i<62;i++)
        {
            for(int j=i;j<62;j++)
            {
                for(int k=j;k<62;k++)
                {
                    for(int p=0;p<62;p++)
                    {
                        ll tmp = 1;
                        tmp *= cnt[i][p][t];
                        tmp %= mod;
                        tmp *= cnt[j][p][t];
                        tmp %= mod;
                        tmp *= cnt[k][p][t];
                        tmp %= mod;
                        Pre[i][j][k][t] += tmp;
                    }
                }
            }
        }
    }

    for(int t=3;t<=10;t++)
    {
        for(int a=0;a<62;a++)
        {
            for(int b=a;b<62;b++)
            {
                for(int c=b;c<62;c++)
                {
                    for(int d=c;d<62;d++)
                    {
                        ll tmp = 1;
                        tmp *= Pre[a][b][c][t];
                        tmp %= mod;
                        tmp *= Pre[a][b][d][t];
                        tmp %= mod;
                        tmp *= Pre[a][c][d][t];
                        tmp %= mod;
                        tmp *= Pre[b][c][d][t];
                        tmp %= mod;

                        if(a == d) tmp *= 1;
                        else if(a == c || b == d) tmp *= 4;
                        else if(a == b && c == d) tmp *= 6;
                        else if(a == b || b == c || c == d) tmp *= 12;
                        else tmp *= 24;
                        ans = (ans + tmp)%mod;
                    }
                }
            }
        }
    }

    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 418 ms 24900 KB Output is correct
2 Correct 410 ms 24988 KB Output is correct
3 Correct 411 ms 25024 KB Output is correct
4 Correct 416 ms 25000 KB Output is correct
5 Correct 410 ms 25008 KB Output is correct
6 Correct 418 ms 25184 KB Output is correct
7 Correct 411 ms 25000 KB Output is correct
8 Correct 415 ms 24996 KB Output is correct
9 Correct 418 ms 25028 KB Output is correct
10 Correct 412 ms 25148 KB Output is correct
11 Correct 407 ms 25032 KB Output is correct
12 Correct 402 ms 24984 KB Output is correct
13 Correct 432 ms 25032 KB Output is correct
14 Correct 409 ms 24988 KB Output is correct
15 Correct 426 ms 24996 KB Output is correct
16 Correct 428 ms 25056 KB Output is correct
17 Correct 411 ms 24992 KB Output is correct
18 Correct 420 ms 25156 KB Output is correct
19 Correct 403 ms 24976 KB Output is correct
20 Correct 405 ms 25036 KB Output is correct
21 Correct 411 ms 25156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 418 ms 24900 KB Output is correct
2 Correct 410 ms 24988 KB Output is correct
3 Correct 411 ms 25024 KB Output is correct
4 Correct 416 ms 25000 KB Output is correct
5 Correct 410 ms 25008 KB Output is correct
6 Correct 418 ms 25184 KB Output is correct
7 Correct 411 ms 25000 KB Output is correct
8 Correct 415 ms 24996 KB Output is correct
9 Correct 418 ms 25028 KB Output is correct
10 Correct 412 ms 25148 KB Output is correct
11 Correct 407 ms 25032 KB Output is correct
12 Correct 402 ms 24984 KB Output is correct
13 Correct 432 ms 25032 KB Output is correct
14 Correct 409 ms 24988 KB Output is correct
15 Correct 426 ms 24996 KB Output is correct
16 Correct 428 ms 25056 KB Output is correct
17 Correct 411 ms 24992 KB Output is correct
18 Correct 420 ms 25156 KB Output is correct
19 Correct 403 ms 24976 KB Output is correct
20 Correct 405 ms 25036 KB Output is correct
21 Correct 411 ms 25156 KB Output is correct
22 Correct 408 ms 26200 KB Output is correct
23 Correct 415 ms 26224 KB Output is correct
24 Correct 404 ms 26252 KB Output is correct
25 Correct 402 ms 26328 KB Output is correct
26 Correct 394 ms 26180 KB Output is correct
27 Correct 409 ms 26336 KB Output is correct
28 Correct 401 ms 26180 KB Output is correct
29 Correct 412 ms 26180 KB Output is correct
30 Correct 393 ms 26180 KB Output is correct
31 Correct 413 ms 26272 KB Output is correct
32 Correct 391 ms 26164 KB Output is correct
33 Correct 404 ms 26336 KB Output is correct
34 Correct 413 ms 26320 KB Output is correct
35 Correct 407 ms 26232 KB Output is correct
36 Correct 415 ms 26160 KB Output is correct
37 Correct 410 ms 26220 KB Output is correct
38 Correct 397 ms 26228 KB Output is correct
39 Correct 404 ms 26192 KB Output is correct
40 Correct 403 ms 26220 KB Output is correct
41 Correct 403 ms 26112 KB Output is correct
42 Correct 408 ms 26200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 418 ms 24900 KB Output is correct
2 Correct 410 ms 24988 KB Output is correct
3 Correct 411 ms 25024 KB Output is correct
4 Correct 416 ms 25000 KB Output is correct
5 Correct 410 ms 25008 KB Output is correct
6 Correct 418 ms 25184 KB Output is correct
7 Correct 411 ms 25000 KB Output is correct
8 Correct 415 ms 24996 KB Output is correct
9 Correct 418 ms 25028 KB Output is correct
10 Correct 412 ms 25148 KB Output is correct
11 Correct 407 ms 25032 KB Output is correct
12 Correct 402 ms 24984 KB Output is correct
13 Correct 432 ms 25032 KB Output is correct
14 Correct 409 ms 24988 KB Output is correct
15 Correct 426 ms 24996 KB Output is correct
16 Correct 428 ms 25056 KB Output is correct
17 Correct 411 ms 24992 KB Output is correct
18 Correct 420 ms 25156 KB Output is correct
19 Correct 403 ms 24976 KB Output is correct
20 Correct 405 ms 25036 KB Output is correct
21 Correct 411 ms 25156 KB Output is correct
22 Correct 408 ms 26200 KB Output is correct
23 Correct 415 ms 26224 KB Output is correct
24 Correct 404 ms 26252 KB Output is correct
25 Correct 402 ms 26328 KB Output is correct
26 Correct 394 ms 26180 KB Output is correct
27 Correct 409 ms 26336 KB Output is correct
28 Correct 401 ms 26180 KB Output is correct
29 Correct 412 ms 26180 KB Output is correct
30 Correct 393 ms 26180 KB Output is correct
31 Correct 413 ms 26272 KB Output is correct
32 Correct 391 ms 26164 KB Output is correct
33 Correct 404 ms 26336 KB Output is correct
34 Correct 413 ms 26320 KB Output is correct
35 Correct 407 ms 26232 KB Output is correct
36 Correct 415 ms 26160 KB Output is correct
37 Correct 410 ms 26220 KB Output is correct
38 Correct 397 ms 26228 KB Output is correct
39 Correct 404 ms 26192 KB Output is correct
40 Correct 403 ms 26220 KB Output is correct
41 Correct 403 ms 26112 KB Output is correct
42 Correct 408 ms 26200 KB Output is correct
43 Correct 401 ms 26420 KB Output is correct
44 Correct 388 ms 26436 KB Output is correct
45 Correct 390 ms 26532 KB Output is correct
46 Correct 392 ms 26596 KB Output is correct
47 Correct 393 ms 26696 KB Output is correct
48 Correct 382 ms 26436 KB Output is correct
49 Correct 399 ms 26460 KB Output is correct
50 Correct 392 ms 26488 KB Output is correct
51 Correct 396 ms 26784 KB Output is correct
52 Correct 381 ms 26440 KB Output is correct
53 Correct 394 ms 26668 KB Output is correct
54 Correct 388 ms 26508 KB Output is correct
55 Correct 403 ms 26612 KB Output is correct
56 Correct 424 ms 26436 KB Output is correct
57 Correct 396 ms 26584 KB Output is correct
58 Correct 388 ms 26564 KB Output is correct
59 Correct 401 ms 26492 KB Output is correct
60 Correct 395 ms 26436 KB Output is correct
61 Correct 410 ms 26488 KB Output is correct
62 Correct 400 ms 26484 KB Output is correct
63 Correct 402 ms 26440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 418 ms 24900 KB Output is correct
2 Correct 410 ms 24988 KB Output is correct
3 Correct 411 ms 25024 KB Output is correct
4 Correct 416 ms 25000 KB Output is correct
5 Correct 410 ms 25008 KB Output is correct
6 Correct 418 ms 25184 KB Output is correct
7 Correct 411 ms 25000 KB Output is correct
8 Correct 415 ms 24996 KB Output is correct
9 Correct 418 ms 25028 KB Output is correct
10 Correct 412 ms 25148 KB Output is correct
11 Correct 407 ms 25032 KB Output is correct
12 Correct 402 ms 24984 KB Output is correct
13 Correct 432 ms 25032 KB Output is correct
14 Correct 409 ms 24988 KB Output is correct
15 Correct 426 ms 24996 KB Output is correct
16 Correct 428 ms 25056 KB Output is correct
17 Correct 411 ms 24992 KB Output is correct
18 Correct 420 ms 25156 KB Output is correct
19 Correct 403 ms 24976 KB Output is correct
20 Correct 405 ms 25036 KB Output is correct
21 Correct 411 ms 25156 KB Output is correct
22 Correct 408 ms 26200 KB Output is correct
23 Correct 415 ms 26224 KB Output is correct
24 Correct 404 ms 26252 KB Output is correct
25 Correct 402 ms 26328 KB Output is correct
26 Correct 394 ms 26180 KB Output is correct
27 Correct 409 ms 26336 KB Output is correct
28 Correct 401 ms 26180 KB Output is correct
29 Correct 412 ms 26180 KB Output is correct
30 Correct 393 ms 26180 KB Output is correct
31 Correct 413 ms 26272 KB Output is correct
32 Correct 391 ms 26164 KB Output is correct
33 Correct 404 ms 26336 KB Output is correct
34 Correct 413 ms 26320 KB Output is correct
35 Correct 407 ms 26232 KB Output is correct
36 Correct 415 ms 26160 KB Output is correct
37 Correct 410 ms 26220 KB Output is correct
38 Correct 397 ms 26228 KB Output is correct
39 Correct 404 ms 26192 KB Output is correct
40 Correct 403 ms 26220 KB Output is correct
41 Correct 403 ms 26112 KB Output is correct
42 Correct 408 ms 26200 KB Output is correct
43 Correct 401 ms 26420 KB Output is correct
44 Correct 388 ms 26436 KB Output is correct
45 Correct 390 ms 26532 KB Output is correct
46 Correct 392 ms 26596 KB Output is correct
47 Correct 393 ms 26696 KB Output is correct
48 Correct 382 ms 26436 KB Output is correct
49 Correct 399 ms 26460 KB Output is correct
50 Correct 392 ms 26488 KB Output is correct
51 Correct 396 ms 26784 KB Output is correct
52 Correct 381 ms 26440 KB Output is correct
53 Correct 394 ms 26668 KB Output is correct
54 Correct 388 ms 26508 KB Output is correct
55 Correct 403 ms 26612 KB Output is correct
56 Correct 424 ms 26436 KB Output is correct
57 Correct 396 ms 26584 KB Output is correct
58 Correct 388 ms 26564 KB Output is correct
59 Correct 401 ms 26492 KB Output is correct
60 Correct 395 ms 26436 KB Output is correct
61 Correct 410 ms 26488 KB Output is correct
62 Correct 400 ms 26484 KB Output is correct
63 Correct 402 ms 26440 KB Output is correct
64 Correct 380 ms 26888 KB Output is correct
65 Correct 384 ms 26984 KB Output is correct
66 Correct 386 ms 26888 KB Output is correct
67 Correct 397 ms 26888 KB Output is correct
68 Correct 383 ms 26816 KB Output is correct
69 Correct 389 ms 26816 KB Output is correct
70 Correct 380 ms 26888 KB Output is correct
71 Correct 408 ms 26888 KB Output is correct
72 Correct 375 ms 26820 KB Output is correct
73 Correct 386 ms 27076 KB Output is correct
74 Correct 377 ms 26820 KB Output is correct
75 Correct 396 ms 27076 KB Output is correct
76 Correct 372 ms 26824 KB Output is correct
77 Correct 391 ms 26968 KB Output is correct
78 Correct 397 ms 26820 KB Output is correct
79 Correct 391 ms 26828 KB Output is correct
80 Correct 385 ms 26820 KB Output is correct
81 Correct 388 ms 26856 KB Output is correct
82 Correct 373 ms 26824 KB Output is correct
83 Correct 407 ms 27000 KB Output is correct
84 Correct 388 ms 26972 KB Output is correct