Submission #446331

# Submission time Handle Problem Language Result Execution time Memory
446331 2021-07-21T14:47:13 Z qwerasdfzxcl Cubeword (CEOI19_cubeword) C++14
100 / 100
206 ms 16312 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#define MX 62

typedef long long ll;
using namespace std;
const int MOD = 998244353;
int cnt[101][101][101];
int a[8], b[12] = {0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7}, c[12] = {1, 2, 3, 0, 4, 5, 6, 7, 5, 6, 7, 4};
int mp[505], val[11][101][101][101];

inline bool chk(string &s){
    int n = s.size();
    for (int i=0;i<n;i++){
        int j = n-1-i;
        if (i>j) break;
        if (s[i]!=s[j]) return 0;
    }
    return 1;
}

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    unordered_set<string> st[11];

    for (int i='a';i<='z';i++){
        mp[i] = i-'a';
    }
    for (int i='A';i<='Z';i++){
        mp[i] = i-'A'+26;
    }
    for (int i='0';i<='9';i++){
        mp[i] = i-'0'+52;
    }
    for (int i=0;i<n;i++){
        string s;
        cin >> s;
        int idx1 = mp[s[0]], idx2 = mp[s.back()], len = s.size();
        cnt[len][idx1][idx2]++;
        cnt[len][idx2][idx1]++;
        if (st[len].find(s)!=st[len].end()){
            cnt[len][idx1][idx2]--;
            cnt[len][idx2][idx1]--;
            continue;
        }
        reverse(s.begin(), s.end());
        if (st[len].find(s)!=st[len].end()){
            cnt[len][idx1][idx2]--;
            cnt[len][idx2][idx1]--;
            continue;
        }
        if (chk(s)) cnt[(int)s.size()][idx2][idx1]--;
        st[len].insert(s);
    }

    for (register int len=3;len<=10;len++){
        for (register int i=0;i<MX;i++){
            for (register int j=i;j<MX;j++){
                for (register int k=j;k<MX;k++){
                    for (register int l=0;l<MX;l++){
                        ll tmp = (ll)cnt[len][i][l] * cnt[len][j][l];
                        if (tmp>=MOD) tmp %= MOD;
                        tmp *= cnt[len][k][l];
                        if (tmp>=MOD) tmp %= MOD;
                        val[len][i][j][k] += tmp;
                        if (val[len][i][j][k]>=MOD) val[len][i][j][k] -= MOD;
                    }
                }
            }
        }
    }
    int ans = 0;
    for (register int len=3;len<=10;len++){
        for (register int i=0;i<MX;i++){
            for (register int j=i;j<MX;j++){
                for (register int k=j;k<MX;k++) if (val[len][i][j][k]){
                    for (register int l=k;l<MX;l++) {
                        ll tmp = val[len][i][j][k];
                        tmp *= val[len][i][j][l];
                        if (tmp>=MOD) tmp %= MOD;
                        tmp *= val[len][i][k][l];
                        if (tmp>=MOD) tmp %= MOD;
                        tmp *= val[len][j][k][l];
                        if (tmp>=MOD) tmp %= MOD;

                        if (i==l);
                        else if (i==k || j==l) tmp *= 4;
                        else if (i==j && k==l) tmp *= 6;
                        else if (i==j || j==k || k==l) tmp *= 12;
                        else tmp *= 24;
                        tmp %= MOD;
                        ans += tmp;
                        if (ans>=MOD) ans -= MOD;
                    }
                }
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

cubeword.cpp: In function 'int main()':
cubeword.cpp:42:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   42 |         int idx1 = mp[s[0]], idx2 = mp[s.back()], len = s.size();
      |                           ^
cubeword.cpp:42:46: warning: array subscript has type 'char' [-Wchar-subscripts]
   42 |         int idx1 = mp[s[0]], idx2 = mp[s.back()], len = s.size();
      |                                        ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 111 ms 15044 KB Output is correct
2 Correct 112 ms 15052 KB Output is correct
3 Correct 122 ms 15044 KB Output is correct
4 Correct 110 ms 15044 KB Output is correct
5 Correct 112 ms 15048 KB Output is correct
6 Correct 122 ms 15104 KB Output is correct
7 Correct 111 ms 15120 KB Output is correct
8 Correct 120 ms 15184 KB Output is correct
9 Correct 118 ms 15120 KB Output is correct
10 Correct 118 ms 15064 KB Output is correct
11 Correct 118 ms 15092 KB Output is correct
12 Correct 117 ms 15084 KB Output is correct
13 Correct 121 ms 15088 KB Output is correct
14 Correct 116 ms 15044 KB Output is correct
15 Correct 118 ms 15056 KB Output is correct
16 Correct 111 ms 15064 KB Output is correct
17 Correct 110 ms 15104 KB Output is correct
18 Correct 123 ms 15148 KB Output is correct
19 Correct 111 ms 15028 KB Output is correct
20 Correct 112 ms 15020 KB Output is correct
21 Correct 113 ms 15172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 15044 KB Output is correct
2 Correct 112 ms 15052 KB Output is correct
3 Correct 122 ms 15044 KB Output is correct
4 Correct 110 ms 15044 KB Output is correct
5 Correct 112 ms 15048 KB Output is correct
6 Correct 122 ms 15104 KB Output is correct
7 Correct 111 ms 15120 KB Output is correct
8 Correct 120 ms 15184 KB Output is correct
9 Correct 118 ms 15120 KB Output is correct
10 Correct 118 ms 15064 KB Output is correct
11 Correct 118 ms 15092 KB Output is correct
12 Correct 117 ms 15084 KB Output is correct
13 Correct 121 ms 15088 KB Output is correct
14 Correct 116 ms 15044 KB Output is correct
15 Correct 118 ms 15056 KB Output is correct
16 Correct 111 ms 15064 KB Output is correct
17 Correct 110 ms 15104 KB Output is correct
18 Correct 123 ms 15148 KB Output is correct
19 Correct 111 ms 15028 KB Output is correct
20 Correct 112 ms 15020 KB Output is correct
21 Correct 113 ms 15172 KB Output is correct
22 Correct 132 ms 15620 KB Output is correct
23 Correct 132 ms 15736 KB Output is correct
24 Correct 116 ms 15660 KB Output is correct
25 Correct 118 ms 15724 KB Output is correct
26 Correct 117 ms 15688 KB Output is correct
27 Correct 117 ms 15732 KB Output is correct
28 Correct 114 ms 15648 KB Output is correct
29 Correct 115 ms 15628 KB Output is correct
30 Correct 124 ms 15636 KB Output is correct
31 Correct 152 ms 15676 KB Output is correct
32 Correct 122 ms 15652 KB Output is correct
33 Correct 125 ms 15740 KB Output is correct
34 Correct 126 ms 15836 KB Output is correct
35 Correct 120 ms 15740 KB Output is correct
36 Correct 116 ms 15684 KB Output is correct
37 Correct 131 ms 15660 KB Output is correct
38 Correct 117 ms 15664 KB Output is correct
39 Correct 118 ms 15636 KB Output is correct
40 Correct 124 ms 15684 KB Output is correct
41 Correct 124 ms 15684 KB Output is correct
42 Correct 117 ms 15708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 15044 KB Output is correct
2 Correct 112 ms 15052 KB Output is correct
3 Correct 122 ms 15044 KB Output is correct
4 Correct 110 ms 15044 KB Output is correct
5 Correct 112 ms 15048 KB Output is correct
6 Correct 122 ms 15104 KB Output is correct
7 Correct 111 ms 15120 KB Output is correct
8 Correct 120 ms 15184 KB Output is correct
9 Correct 118 ms 15120 KB Output is correct
10 Correct 118 ms 15064 KB Output is correct
11 Correct 118 ms 15092 KB Output is correct
12 Correct 117 ms 15084 KB Output is correct
13 Correct 121 ms 15088 KB Output is correct
14 Correct 116 ms 15044 KB Output is correct
15 Correct 118 ms 15056 KB Output is correct
16 Correct 111 ms 15064 KB Output is correct
17 Correct 110 ms 15104 KB Output is correct
18 Correct 123 ms 15148 KB Output is correct
19 Correct 111 ms 15028 KB Output is correct
20 Correct 112 ms 15020 KB Output is correct
21 Correct 113 ms 15172 KB Output is correct
22 Correct 132 ms 15620 KB Output is correct
23 Correct 132 ms 15736 KB Output is correct
24 Correct 116 ms 15660 KB Output is correct
25 Correct 118 ms 15724 KB Output is correct
26 Correct 117 ms 15688 KB Output is correct
27 Correct 117 ms 15732 KB Output is correct
28 Correct 114 ms 15648 KB Output is correct
29 Correct 115 ms 15628 KB Output is correct
30 Correct 124 ms 15636 KB Output is correct
31 Correct 152 ms 15676 KB Output is correct
32 Correct 122 ms 15652 KB Output is correct
33 Correct 125 ms 15740 KB Output is correct
34 Correct 126 ms 15836 KB Output is correct
35 Correct 120 ms 15740 KB Output is correct
36 Correct 116 ms 15684 KB Output is correct
37 Correct 131 ms 15660 KB Output is correct
38 Correct 117 ms 15664 KB Output is correct
39 Correct 118 ms 15636 KB Output is correct
40 Correct 124 ms 15684 KB Output is correct
41 Correct 124 ms 15684 KB Output is correct
42 Correct 117 ms 15708 KB Output is correct
43 Correct 138 ms 15968 KB Output is correct
44 Correct 162 ms 15888 KB Output is correct
45 Correct 151 ms 15960 KB Output is correct
46 Correct 133 ms 15940 KB Output is correct
47 Correct 143 ms 15980 KB Output is correct
48 Correct 141 ms 15992 KB Output is correct
49 Correct 145 ms 15940 KB Output is correct
50 Correct 149 ms 15924 KB Output is correct
51 Correct 135 ms 16068 KB Output is correct
52 Correct 153 ms 15988 KB Output is correct
53 Correct 149 ms 15900 KB Output is correct
54 Correct 131 ms 15940 KB Output is correct
55 Correct 131 ms 15852 KB Output is correct
56 Correct 145 ms 15908 KB Output is correct
57 Correct 144 ms 15964 KB Output is correct
58 Correct 150 ms 15948 KB Output is correct
59 Correct 133 ms 15864 KB Output is correct
60 Correct 139 ms 15952 KB Output is correct
61 Correct 149 ms 15860 KB Output is correct
62 Correct 140 ms 15936 KB Output is correct
63 Correct 135 ms 15868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 15044 KB Output is correct
2 Correct 112 ms 15052 KB Output is correct
3 Correct 122 ms 15044 KB Output is correct
4 Correct 110 ms 15044 KB Output is correct
5 Correct 112 ms 15048 KB Output is correct
6 Correct 122 ms 15104 KB Output is correct
7 Correct 111 ms 15120 KB Output is correct
8 Correct 120 ms 15184 KB Output is correct
9 Correct 118 ms 15120 KB Output is correct
10 Correct 118 ms 15064 KB Output is correct
11 Correct 118 ms 15092 KB Output is correct
12 Correct 117 ms 15084 KB Output is correct
13 Correct 121 ms 15088 KB Output is correct
14 Correct 116 ms 15044 KB Output is correct
15 Correct 118 ms 15056 KB Output is correct
16 Correct 111 ms 15064 KB Output is correct
17 Correct 110 ms 15104 KB Output is correct
18 Correct 123 ms 15148 KB Output is correct
19 Correct 111 ms 15028 KB Output is correct
20 Correct 112 ms 15020 KB Output is correct
21 Correct 113 ms 15172 KB Output is correct
22 Correct 132 ms 15620 KB Output is correct
23 Correct 132 ms 15736 KB Output is correct
24 Correct 116 ms 15660 KB Output is correct
25 Correct 118 ms 15724 KB Output is correct
26 Correct 117 ms 15688 KB Output is correct
27 Correct 117 ms 15732 KB Output is correct
28 Correct 114 ms 15648 KB Output is correct
29 Correct 115 ms 15628 KB Output is correct
30 Correct 124 ms 15636 KB Output is correct
31 Correct 152 ms 15676 KB Output is correct
32 Correct 122 ms 15652 KB Output is correct
33 Correct 125 ms 15740 KB Output is correct
34 Correct 126 ms 15836 KB Output is correct
35 Correct 120 ms 15740 KB Output is correct
36 Correct 116 ms 15684 KB Output is correct
37 Correct 131 ms 15660 KB Output is correct
38 Correct 117 ms 15664 KB Output is correct
39 Correct 118 ms 15636 KB Output is correct
40 Correct 124 ms 15684 KB Output is correct
41 Correct 124 ms 15684 KB Output is correct
42 Correct 117 ms 15708 KB Output is correct
43 Correct 138 ms 15968 KB Output is correct
44 Correct 162 ms 15888 KB Output is correct
45 Correct 151 ms 15960 KB Output is correct
46 Correct 133 ms 15940 KB Output is correct
47 Correct 143 ms 15980 KB Output is correct
48 Correct 141 ms 15992 KB Output is correct
49 Correct 145 ms 15940 KB Output is correct
50 Correct 149 ms 15924 KB Output is correct
51 Correct 135 ms 16068 KB Output is correct
52 Correct 153 ms 15988 KB Output is correct
53 Correct 149 ms 15900 KB Output is correct
54 Correct 131 ms 15940 KB Output is correct
55 Correct 131 ms 15852 KB Output is correct
56 Correct 145 ms 15908 KB Output is correct
57 Correct 144 ms 15964 KB Output is correct
58 Correct 150 ms 15948 KB Output is correct
59 Correct 133 ms 15864 KB Output is correct
60 Correct 139 ms 15952 KB Output is correct
61 Correct 149 ms 15860 KB Output is correct
62 Correct 140 ms 15936 KB Output is correct
63 Correct 135 ms 15868 KB Output is correct
64 Correct 188 ms 16220 KB Output is correct
65 Correct 193 ms 16188 KB Output is correct
66 Correct 197 ms 16212 KB Output is correct
67 Correct 176 ms 16216 KB Output is correct
68 Correct 184 ms 16212 KB Output is correct
69 Correct 190 ms 16212 KB Output is correct
70 Correct 178 ms 16164 KB Output is correct
71 Correct 174 ms 16196 KB Output is correct
72 Correct 180 ms 16284 KB Output is correct
73 Correct 205 ms 16200 KB Output is correct
74 Correct 182 ms 16108 KB Output is correct
75 Correct 190 ms 16196 KB Output is correct
76 Correct 190 ms 16300 KB Output is correct
77 Correct 205 ms 16216 KB Output is correct
78 Correct 175 ms 16180 KB Output is correct
79 Correct 183 ms 16160 KB Output is correct
80 Correct 191 ms 16200 KB Output is correct
81 Correct 188 ms 16312 KB Output is correct
82 Correct 184 ms 16172 KB Output is correct
83 Correct 206 ms 16212 KB Output is correct
84 Correct 181 ms 16208 KB Output is correct