답안 #597544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
597544 2022-07-16T09:40:44 Z Valaki2 Cubeword (CEOI19_cubeword) C++14
84 / 100
240 ms 31180 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")

#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

const int mod = 998244353;

const int maxn = 2e5;
const int min_l = 3;
const int max_l = 10;
const int max_ch = 32;

int combinations[max_l + 1][max_ch][max_ch];

int convert(char ch) {
    if(ch >= 'a' && ch <= 'p') {
        return ch - 'a';
    }
    if(ch >= 'q' && ch <= 'z') {
        return ch - 'q' + 32;
    }
    if(ch >= 'A' && ch <= 'P') {
        return ch - 'A' + 16;
    }
    if(ch >= 'Q' && ch <= 'Z') {
        return ch - 'Q' + 42;
    }
    if(ch >= '0' && ch <= '9') {
        return ch - '0' + 52;
    }
}

int n;
vector<string> v;
int ans;

int len;
vector<int> corners;
// vector<pii > neighbours;
int number[max_ch][max_ch][max_ch];
int prec[max_ch][max_ch][max_ch][max_ch];

int try_scenario() {
    int res = 1;
    for(int i = 1; i <= 3; i++) {
        res = (res * combinations[len][corners[0]][corners[i]]) % mod;
    }
    return res;
}

void backtrack(int corner_id) {
    if(corner_id == 4) {
        number[corners[1]][corners[2]][corners[3]] = (number[corners[1]][corners[2]][corners[3]] + try_scenario()) % mod;
    } else {
        for(corners[corner_id] = 0; corners[corner_id] < max_ch; corners[corner_id]++) {
            backtrack(corner_id + 1);
        }
    }
}

void solve() {
    cin >> n;
    //n = 1;
    v.assign(2 * n, "");
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        //v[i] = "cabac";
        v[i + n] = v[i];
        reverse(v[i + n].begin(), v[i + n].end());
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    n = (int) v.size();
    for(int i = 0; i < n; i++) {
        int cur_length = (int) v[i].size();
        int cur_first = convert(v[i].front());
        int cur_last = convert(v[i].back());
        combinations[cur_length][cur_first][cur_last]++;
    }
    /*for(int i = 0; i < 8; i++) {
        for(int j = i + 1; j < 8; j++) {
            if(__builtin_popcount(i ^ j) == 1) {
                neighbours.pb(mp(i, j));
            }
        }
    }*/
    corners.assign(4, 0);
    for(len = min_l; len <= max_l; len++) {
        // reset everything
        for(int i = 0; i < max_ch; i++) {
            for(int j = 0; j < max_ch; j++) {
                for(int k = 0; k < max_ch; k++) {
                    number[i][j][k] = 0;
                    for(int l = 0; l < max_ch; l++) {
                        prec[i][j][k][l] = combinations[len][i][j] * combinations[len][j][k] % mod * combinations[len][k][l] % mod;
                    }
                }
            }
        }
        backtrack(0);
        for(int a = 0; a < max_ch; a++) {
            for(int b = 0; b < max_ch; b++) {
                for(int c = 0; c < max_ch; c++) {
                    for(int d = 0; d < max_ch; d++) {
                        ans = (ans +
                                 number[a][b][c] % mod
                               * number[a][b][d] % mod
                               * number[a][c][d] % mod
                               * number[b][c][d] % mod) % mod;
                    }
                }
            }
        }
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Compilation message

cubeword.cpp: In function 'long long int convert(char)':
cubeword.cpp:40:1: warning: control reaches end of non-void function [-Wreturn-type]
   40 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 221 ms 15908 KB Output is correct
2 Correct 212 ms 15928 KB Output is correct
3 Correct 220 ms 15820 KB Output is correct
4 Correct 213 ms 15932 KB Output is correct
5 Correct 215 ms 15892 KB Output is correct
6 Correct 207 ms 15896 KB Output is correct
7 Correct 233 ms 15908 KB Output is correct
8 Correct 226 ms 15916 KB Output is correct
9 Correct 210 ms 15892 KB Output is correct
10 Correct 213 ms 15896 KB Output is correct
11 Correct 221 ms 15876 KB Output is correct
12 Correct 205 ms 15924 KB Output is correct
13 Correct 209 ms 15928 KB Output is correct
14 Correct 219 ms 15896 KB Output is correct
15 Correct 223 ms 15900 KB Output is correct
16 Correct 211 ms 15900 KB Output is correct
17 Correct 238 ms 15828 KB Output is correct
18 Correct 208 ms 15904 KB Output is correct
19 Correct 215 ms 15896 KB Output is correct
20 Correct 233 ms 15896 KB Output is correct
21 Correct 206 ms 15820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 221 ms 15908 KB Output is correct
2 Correct 212 ms 15928 KB Output is correct
3 Correct 220 ms 15820 KB Output is correct
4 Correct 213 ms 15932 KB Output is correct
5 Correct 215 ms 15892 KB Output is correct
6 Correct 207 ms 15896 KB Output is correct
7 Correct 233 ms 15908 KB Output is correct
8 Correct 226 ms 15916 KB Output is correct
9 Correct 210 ms 15892 KB Output is correct
10 Correct 213 ms 15896 KB Output is correct
11 Correct 221 ms 15876 KB Output is correct
12 Correct 205 ms 15924 KB Output is correct
13 Correct 209 ms 15928 KB Output is correct
14 Correct 219 ms 15896 KB Output is correct
15 Correct 223 ms 15900 KB Output is correct
16 Correct 211 ms 15900 KB Output is correct
17 Correct 238 ms 15828 KB Output is correct
18 Correct 208 ms 15904 KB Output is correct
19 Correct 215 ms 15896 KB Output is correct
20 Correct 233 ms 15896 KB Output is correct
21 Correct 206 ms 15820 KB Output is correct
22 Correct 205 ms 15784 KB Output is correct
23 Correct 211 ms 15804 KB Output is correct
24 Correct 206 ms 15816 KB Output is correct
25 Correct 209 ms 15804 KB Output is correct
26 Correct 240 ms 15808 KB Output is correct
27 Correct 210 ms 15824 KB Output is correct
28 Correct 203 ms 15816 KB Output is correct
29 Correct 207 ms 15820 KB Output is correct
30 Correct 229 ms 15812 KB Output is correct
31 Correct 204 ms 15808 KB Output is correct
32 Correct 211 ms 15812 KB Output is correct
33 Correct 214 ms 15816 KB Output is correct
34 Correct 222 ms 15836 KB Output is correct
35 Correct 208 ms 15812 KB Output is correct
36 Correct 206 ms 15808 KB Output is correct
37 Correct 216 ms 15820 KB Output is correct
38 Correct 210 ms 15808 KB Output is correct
39 Correct 204 ms 15932 KB Output is correct
40 Correct 219 ms 15808 KB Output is correct
41 Correct 203 ms 15820 KB Output is correct
42 Correct 205 ms 15808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 221 ms 15908 KB Output is correct
2 Correct 212 ms 15928 KB Output is correct
3 Correct 220 ms 15820 KB Output is correct
4 Correct 213 ms 15932 KB Output is correct
5 Correct 215 ms 15892 KB Output is correct
6 Correct 207 ms 15896 KB Output is correct
7 Correct 233 ms 15908 KB Output is correct
8 Correct 226 ms 15916 KB Output is correct
9 Correct 210 ms 15892 KB Output is correct
10 Correct 213 ms 15896 KB Output is correct
11 Correct 221 ms 15876 KB Output is correct
12 Correct 205 ms 15924 KB Output is correct
13 Correct 209 ms 15928 KB Output is correct
14 Correct 219 ms 15896 KB Output is correct
15 Correct 223 ms 15900 KB Output is correct
16 Correct 211 ms 15900 KB Output is correct
17 Correct 238 ms 15828 KB Output is correct
18 Correct 208 ms 15904 KB Output is correct
19 Correct 215 ms 15896 KB Output is correct
20 Correct 233 ms 15896 KB Output is correct
21 Correct 206 ms 15820 KB Output is correct
22 Correct 205 ms 15784 KB Output is correct
23 Correct 211 ms 15804 KB Output is correct
24 Correct 206 ms 15816 KB Output is correct
25 Correct 209 ms 15804 KB Output is correct
26 Correct 240 ms 15808 KB Output is correct
27 Correct 210 ms 15824 KB Output is correct
28 Correct 203 ms 15816 KB Output is correct
29 Correct 207 ms 15820 KB Output is correct
30 Correct 229 ms 15812 KB Output is correct
31 Correct 204 ms 15808 KB Output is correct
32 Correct 211 ms 15812 KB Output is correct
33 Correct 214 ms 15816 KB Output is correct
34 Correct 222 ms 15836 KB Output is correct
35 Correct 208 ms 15812 KB Output is correct
36 Correct 206 ms 15808 KB Output is correct
37 Correct 216 ms 15820 KB Output is correct
38 Correct 210 ms 15808 KB Output is correct
39 Correct 204 ms 15932 KB Output is correct
40 Correct 219 ms 15808 KB Output is correct
41 Correct 203 ms 15820 KB Output is correct
42 Correct 205 ms 15808 KB Output is correct
43 Correct 236 ms 15780 KB Output is correct
44 Correct 223 ms 15816 KB Output is correct
45 Correct 208 ms 15780 KB Output is correct
46 Correct 218 ms 15784 KB Output is correct
47 Correct 221 ms 15824 KB Output is correct
48 Correct 211 ms 15796 KB Output is correct
49 Correct 223 ms 15776 KB Output is correct
50 Correct 208 ms 15804 KB Output is correct
51 Correct 222 ms 15792 KB Output is correct
52 Correct 216 ms 15824 KB Output is correct
53 Correct 208 ms 15820 KB Output is correct
54 Correct 206 ms 15800 KB Output is correct
55 Correct 215 ms 15820 KB Output is correct
56 Correct 210 ms 15796 KB Output is correct
57 Correct 206 ms 15780 KB Output is correct
58 Correct 232 ms 15780 KB Output is correct
59 Correct 204 ms 15796 KB Output is correct
60 Correct 206 ms 15780 KB Output is correct
61 Correct 205 ms 15776 KB Output is correct
62 Correct 212 ms 15796 KB Output is correct
63 Correct 223 ms 15784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 221 ms 15908 KB Output is correct
2 Correct 212 ms 15928 KB Output is correct
3 Correct 220 ms 15820 KB Output is correct
4 Correct 213 ms 15932 KB Output is correct
5 Correct 215 ms 15892 KB Output is correct
6 Correct 207 ms 15896 KB Output is correct
7 Correct 233 ms 15908 KB Output is correct
8 Correct 226 ms 15916 KB Output is correct
9 Correct 210 ms 15892 KB Output is correct
10 Correct 213 ms 15896 KB Output is correct
11 Correct 221 ms 15876 KB Output is correct
12 Correct 205 ms 15924 KB Output is correct
13 Correct 209 ms 15928 KB Output is correct
14 Correct 219 ms 15896 KB Output is correct
15 Correct 223 ms 15900 KB Output is correct
16 Correct 211 ms 15900 KB Output is correct
17 Correct 238 ms 15828 KB Output is correct
18 Correct 208 ms 15904 KB Output is correct
19 Correct 215 ms 15896 KB Output is correct
20 Correct 233 ms 15896 KB Output is correct
21 Correct 206 ms 15820 KB Output is correct
22 Correct 205 ms 15784 KB Output is correct
23 Correct 211 ms 15804 KB Output is correct
24 Correct 206 ms 15816 KB Output is correct
25 Correct 209 ms 15804 KB Output is correct
26 Correct 240 ms 15808 KB Output is correct
27 Correct 210 ms 15824 KB Output is correct
28 Correct 203 ms 15816 KB Output is correct
29 Correct 207 ms 15820 KB Output is correct
30 Correct 229 ms 15812 KB Output is correct
31 Correct 204 ms 15808 KB Output is correct
32 Correct 211 ms 15812 KB Output is correct
33 Correct 214 ms 15816 KB Output is correct
34 Correct 222 ms 15836 KB Output is correct
35 Correct 208 ms 15812 KB Output is correct
36 Correct 206 ms 15808 KB Output is correct
37 Correct 216 ms 15820 KB Output is correct
38 Correct 210 ms 15808 KB Output is correct
39 Correct 204 ms 15932 KB Output is correct
40 Correct 219 ms 15808 KB Output is correct
41 Correct 203 ms 15820 KB Output is correct
42 Correct 205 ms 15808 KB Output is correct
43 Correct 236 ms 15780 KB Output is correct
44 Correct 223 ms 15816 KB Output is correct
45 Correct 208 ms 15780 KB Output is correct
46 Correct 218 ms 15784 KB Output is correct
47 Correct 221 ms 15824 KB Output is correct
48 Correct 211 ms 15796 KB Output is correct
49 Correct 223 ms 15776 KB Output is correct
50 Correct 208 ms 15804 KB Output is correct
51 Correct 222 ms 15792 KB Output is correct
52 Correct 216 ms 15824 KB Output is correct
53 Correct 208 ms 15820 KB Output is correct
54 Correct 206 ms 15800 KB Output is correct
55 Correct 215 ms 15820 KB Output is correct
56 Correct 210 ms 15796 KB Output is correct
57 Correct 206 ms 15780 KB Output is correct
58 Correct 232 ms 15780 KB Output is correct
59 Correct 204 ms 15796 KB Output is correct
60 Correct 206 ms 15780 KB Output is correct
61 Correct 205 ms 15776 KB Output is correct
62 Correct 212 ms 15796 KB Output is correct
63 Correct 223 ms 15784 KB Output is correct
64 Runtime error 220 ms 31180 KB Execution killed with signal 11
65 Halted 0 ms 0 KB -