Submission #779940

# Submission time Handle Problem Language Result Execution time Memory
779940 2023-07-12T03:35:46 Z mmk Cubeword (CEOI19_cubeword) C++14
100 / 100
940 ms 17448 KB
#include<bits/stdc++.h>
#define int long long

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

const int ALP = 62;
const int MOD = 998244353;
using namespace std;
unordered_set<string> words[15];

int getId(char c)
{
    if(c <= '9') return c - '0';

    if(c <= 'Z') return c - 'A' + '9' - '0' + 1;

    if(c <= 'z') return c - 'a' + 'Z' - 'A' + 1 + '9' - '0' + 1;
}

int calc(int sz)
{
    if(words[sz].size() == 0) return 0;
    int ans = 0;
    int freq[ALP][ALP][ALP] = {0};
    int cont[ALP][ALP] = {0};

    for(auto cur : words[sz])
    {
        int beg = getId(cur[0]);
        int abongabingers = getId(cur.back());

        cont[beg][abongabingers]++;
    }

    for(int a = 0; a < ALP; a++)
    {
        for(int b = 0; b < ALP; b++)
        {
            for(int c = 0; c < ALP; c++)
            {
                for(int end = 0; end < ALP; end++)
                {
                    freq[a][b][c] += (cont[a][end]*cont[b][end]*cont[c][end])%MOD;
                }
            }
        }
    }

    for(int a = 0; a < ALP; a++)
    {
        for(int b = 0; b < ALP; b++)
        {
            for(int c = 0; c < ALP; c++)
            {
                for(int d = 0; d < ALP; d++)
                {
                    int add = 1;

                    add *= freq[a][b][c]; add %= MOD;
                    add *= freq[a][c][d]; add %= MOD;
                    add *= freq[b][c][d]; add %= MOD;
                    add *= freq[a][b][d]; add %= MOD;

                    ans += add;

                    ans %= MOD;
                }
            }
        }
    }
    return ans;
}

int32_t main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n; cin >> n;

    for(int i = 0; i < n; i++)
    {
        string aux; cin >> aux;

        string rev = aux;
        reverse(rev.begin(),rev.end());

        words[aux.size()].insert(aux);
        words[aux.size()].insert(rev);
    }

    int resp = 0;
    for(int i = 3; i <= 10; i++)
    {
        resp += calc(i);
        resp %= MOD;
    }

    cout << resp;
}

Compilation message

cubeword.cpp: In function 'long long int getId(char)':
cubeword.cpp:19:1: warning: control reaches end of non-void function [-Wreturn-type]
   19 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 870 ms 15576 KB Output is correct
2 Correct 882 ms 15620 KB Output is correct
3 Correct 917 ms 15572 KB Output is correct
4 Correct 869 ms 15552 KB Output is correct
5 Correct 849 ms 15564 KB Output is correct
6 Correct 861 ms 15564 KB Output is correct
7 Correct 871 ms 15596 KB Output is correct
8 Correct 882 ms 15576 KB Output is correct
9 Correct 902 ms 15640 KB Output is correct
10 Correct 897 ms 15572 KB Output is correct
11 Correct 854 ms 15568 KB Output is correct
12 Correct 876 ms 15560 KB Output is correct
13 Correct 892 ms 15580 KB Output is correct
14 Correct 890 ms 15572 KB Output is correct
15 Correct 881 ms 15572 KB Output is correct
16 Correct 863 ms 15560 KB Output is correct
17 Correct 857 ms 15572 KB Output is correct
18 Correct 858 ms 15560 KB Output is correct
19 Correct 877 ms 15552 KB Output is correct
20 Correct 871 ms 15568 KB Output is correct
21 Correct 894 ms 15552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 870 ms 15576 KB Output is correct
2 Correct 882 ms 15620 KB Output is correct
3 Correct 917 ms 15572 KB Output is correct
4 Correct 869 ms 15552 KB Output is correct
5 Correct 849 ms 15564 KB Output is correct
6 Correct 861 ms 15564 KB Output is correct
7 Correct 871 ms 15596 KB Output is correct
8 Correct 882 ms 15576 KB Output is correct
9 Correct 902 ms 15640 KB Output is correct
10 Correct 897 ms 15572 KB Output is correct
11 Correct 854 ms 15568 KB Output is correct
12 Correct 876 ms 15560 KB Output is correct
13 Correct 892 ms 15580 KB Output is correct
14 Correct 890 ms 15572 KB Output is correct
15 Correct 881 ms 15572 KB Output is correct
16 Correct 863 ms 15560 KB Output is correct
17 Correct 857 ms 15572 KB Output is correct
18 Correct 858 ms 15560 KB Output is correct
19 Correct 877 ms 15552 KB Output is correct
20 Correct 871 ms 15568 KB Output is correct
21 Correct 894 ms 15552 KB Output is correct
22 Correct 894 ms 16700 KB Output is correct
23 Correct 885 ms 16704 KB Output is correct
24 Correct 894 ms 16716 KB Output is correct
25 Correct 866 ms 16696 KB Output is correct
26 Correct 886 ms 16692 KB Output is correct
27 Correct 886 ms 16688 KB Output is correct
28 Correct 887 ms 16700 KB Output is correct
29 Correct 898 ms 16700 KB Output is correct
30 Correct 860 ms 16700 KB Output is correct
31 Correct 885 ms 16664 KB Output is correct
32 Correct 854 ms 16692 KB Output is correct
33 Correct 868 ms 16696 KB Output is correct
34 Correct 861 ms 16720 KB Output is correct
35 Correct 873 ms 16700 KB Output is correct
36 Correct 862 ms 16708 KB Output is correct
37 Correct 863 ms 16704 KB Output is correct
38 Correct 899 ms 16700 KB Output is correct
39 Correct 893 ms 16704 KB Output is correct
40 Correct 874 ms 16720 KB Output is correct
41 Correct 862 ms 16696 KB Output is correct
42 Correct 897 ms 16700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 870 ms 15576 KB Output is correct
2 Correct 882 ms 15620 KB Output is correct
3 Correct 917 ms 15572 KB Output is correct
4 Correct 869 ms 15552 KB Output is correct
5 Correct 849 ms 15564 KB Output is correct
6 Correct 861 ms 15564 KB Output is correct
7 Correct 871 ms 15596 KB Output is correct
8 Correct 882 ms 15576 KB Output is correct
9 Correct 902 ms 15640 KB Output is correct
10 Correct 897 ms 15572 KB Output is correct
11 Correct 854 ms 15568 KB Output is correct
12 Correct 876 ms 15560 KB Output is correct
13 Correct 892 ms 15580 KB Output is correct
14 Correct 890 ms 15572 KB Output is correct
15 Correct 881 ms 15572 KB Output is correct
16 Correct 863 ms 15560 KB Output is correct
17 Correct 857 ms 15572 KB Output is correct
18 Correct 858 ms 15560 KB Output is correct
19 Correct 877 ms 15552 KB Output is correct
20 Correct 871 ms 15568 KB Output is correct
21 Correct 894 ms 15552 KB Output is correct
22 Correct 894 ms 16700 KB Output is correct
23 Correct 885 ms 16704 KB Output is correct
24 Correct 894 ms 16716 KB Output is correct
25 Correct 866 ms 16696 KB Output is correct
26 Correct 886 ms 16692 KB Output is correct
27 Correct 886 ms 16688 KB Output is correct
28 Correct 887 ms 16700 KB Output is correct
29 Correct 898 ms 16700 KB Output is correct
30 Correct 860 ms 16700 KB Output is correct
31 Correct 885 ms 16664 KB Output is correct
32 Correct 854 ms 16692 KB Output is correct
33 Correct 868 ms 16696 KB Output is correct
34 Correct 861 ms 16720 KB Output is correct
35 Correct 873 ms 16700 KB Output is correct
36 Correct 862 ms 16708 KB Output is correct
37 Correct 863 ms 16704 KB Output is correct
38 Correct 899 ms 16700 KB Output is correct
39 Correct 893 ms 16704 KB Output is correct
40 Correct 874 ms 16720 KB Output is correct
41 Correct 862 ms 16696 KB Output is correct
42 Correct 897 ms 16700 KB Output is correct
43 Correct 865 ms 17004 KB Output is correct
44 Correct 871 ms 17008 KB Output is correct
45 Correct 886 ms 16992 KB Output is correct
46 Correct 904 ms 16988 KB Output is correct
47 Correct 873 ms 17152 KB Output is correct
48 Correct 903 ms 16996 KB Output is correct
49 Correct 893 ms 16928 KB Output is correct
50 Correct 870 ms 17024 KB Output is correct
51 Correct 875 ms 17104 KB Output is correct
52 Correct 892 ms 16992 KB Output is correct
53 Correct 891 ms 17004 KB Output is correct
54 Correct 866 ms 16996 KB Output is correct
55 Correct 863 ms 16988 KB Output is correct
56 Correct 910 ms 17004 KB Output is correct
57 Correct 940 ms 16984 KB Output is correct
58 Correct 865 ms 17000 KB Output is correct
59 Correct 879 ms 16988 KB Output is correct
60 Correct 865 ms 16984 KB Output is correct
61 Correct 883 ms 16996 KB Output is correct
62 Correct 854 ms 16984 KB Output is correct
63 Correct 879 ms 16992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 870 ms 15576 KB Output is correct
2 Correct 882 ms 15620 KB Output is correct
3 Correct 917 ms 15572 KB Output is correct
4 Correct 869 ms 15552 KB Output is correct
5 Correct 849 ms 15564 KB Output is correct
6 Correct 861 ms 15564 KB Output is correct
7 Correct 871 ms 15596 KB Output is correct
8 Correct 882 ms 15576 KB Output is correct
9 Correct 902 ms 15640 KB Output is correct
10 Correct 897 ms 15572 KB Output is correct
11 Correct 854 ms 15568 KB Output is correct
12 Correct 876 ms 15560 KB Output is correct
13 Correct 892 ms 15580 KB Output is correct
14 Correct 890 ms 15572 KB Output is correct
15 Correct 881 ms 15572 KB Output is correct
16 Correct 863 ms 15560 KB Output is correct
17 Correct 857 ms 15572 KB Output is correct
18 Correct 858 ms 15560 KB Output is correct
19 Correct 877 ms 15552 KB Output is correct
20 Correct 871 ms 15568 KB Output is correct
21 Correct 894 ms 15552 KB Output is correct
22 Correct 894 ms 16700 KB Output is correct
23 Correct 885 ms 16704 KB Output is correct
24 Correct 894 ms 16716 KB Output is correct
25 Correct 866 ms 16696 KB Output is correct
26 Correct 886 ms 16692 KB Output is correct
27 Correct 886 ms 16688 KB Output is correct
28 Correct 887 ms 16700 KB Output is correct
29 Correct 898 ms 16700 KB Output is correct
30 Correct 860 ms 16700 KB Output is correct
31 Correct 885 ms 16664 KB Output is correct
32 Correct 854 ms 16692 KB Output is correct
33 Correct 868 ms 16696 KB Output is correct
34 Correct 861 ms 16720 KB Output is correct
35 Correct 873 ms 16700 KB Output is correct
36 Correct 862 ms 16708 KB Output is correct
37 Correct 863 ms 16704 KB Output is correct
38 Correct 899 ms 16700 KB Output is correct
39 Correct 893 ms 16704 KB Output is correct
40 Correct 874 ms 16720 KB Output is correct
41 Correct 862 ms 16696 KB Output is correct
42 Correct 897 ms 16700 KB Output is correct
43 Correct 865 ms 17004 KB Output is correct
44 Correct 871 ms 17008 KB Output is correct
45 Correct 886 ms 16992 KB Output is correct
46 Correct 904 ms 16988 KB Output is correct
47 Correct 873 ms 17152 KB Output is correct
48 Correct 903 ms 16996 KB Output is correct
49 Correct 893 ms 16928 KB Output is correct
50 Correct 870 ms 17024 KB Output is correct
51 Correct 875 ms 17104 KB Output is correct
52 Correct 892 ms 16992 KB Output is correct
53 Correct 891 ms 17004 KB Output is correct
54 Correct 866 ms 16996 KB Output is correct
55 Correct 863 ms 16988 KB Output is correct
56 Correct 910 ms 17004 KB Output is correct
57 Correct 940 ms 16984 KB Output is correct
58 Correct 865 ms 17000 KB Output is correct
59 Correct 879 ms 16988 KB Output is correct
60 Correct 865 ms 16984 KB Output is correct
61 Correct 883 ms 16996 KB Output is correct
62 Correct 854 ms 16984 KB Output is correct
63 Correct 879 ms 16992 KB Output is correct
64 Correct 859 ms 17348 KB Output is correct
65 Correct 860 ms 17352 KB Output is correct
66 Correct 873 ms 17356 KB Output is correct
67 Correct 862 ms 17328 KB Output is correct
68 Correct 873 ms 17352 KB Output is correct
69 Correct 867 ms 17348 KB Output is correct
70 Correct 902 ms 17356 KB Output is correct
71 Correct 909 ms 17256 KB Output is correct
72 Correct 870 ms 17320 KB Output is correct
73 Correct 874 ms 17352 KB Output is correct
74 Correct 870 ms 17348 KB Output is correct
75 Correct 893 ms 17344 KB Output is correct
76 Correct 876 ms 17344 KB Output is correct
77 Correct 886 ms 17344 KB Output is correct
78 Correct 867 ms 17448 KB Output is correct
79 Correct 871 ms 17348 KB Output is correct
80 Correct 899 ms 17356 KB Output is correct
81 Correct 901 ms 17348 KB Output is correct
82 Correct 862 ms 17348 KB Output is correct
83 Correct 866 ms 17356 KB Output is correct
84 Correct 849 ms 17332 KB Output is correct