Submission #579200

# Submission time Handle Problem Language Result Execution time Memory
579200 2022-06-18T13:16:51 Z talant117408 Cubeword (CEOI19_cubeword) C++17
100 / 100
561 ms 29360 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define long                unsigned long 
#define pb                  push_back
#define mp                  make_pair
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define lb                  lower_bound
#define ub                  upper_bound
#define sz(v)               int((v).size())
#define do_not_disturb      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl                '\n'

const int mod = 998244353;

ll add(ll a, ll b) {
    return ((a + b) % mod + mod) % mod;
}

ll mult(ll a, ll b) {
    return ((a * b) % mod + mod) % mod;
}

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

const int CH = 62;
ll ways[11][CH][CH], side[11][CH][CH][CH];

void solve() {
    int n;
    cin >> n;
    vector <string> v;
    set <string> st;
    
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        auto s2 = s;
        reverse(all(s2));
        int last = sz(st);
        st.insert(s2);
        if (last != sz(st)) {
            st.insert(s);
            v.pb(s);
        }
    }
    vector <int> used(11);
    for (auto to : v) {
        if (to[0] == to.back()) {
            auto to2 = to;
            reverse(all(to2));
            ways[sz(to)][index(to.back())][index(to.back())] += 1 + (to != to2);
        }
        else {
            ways[sz(to)][index(to[0])][index(to.back())]++;
            ways[sz(to)][index(to.back())][index(to[0])]++;
        }
        used[sz(to)] = 1;
    }
    for (int j = 3; j <= 10; j++) {
        if (used[j] == 0) continue;
        for (int j2 = 0; j2 < CH; j2++)
        for (int j3 = j2; j3 < CH; j3++)
        for (int j4 = j3; j4 < CH; j4++) {
            for (int j1 = 0; j1 < CH; j1++) 
            side[j][j2][j3][j4] = add(side[j][j2][j3][j4], mult(mult(ways[j][j1][j2], ways[j][j1][j3]), ways[j][j1][j4]));
        }
    }
    
    ll ans = 0;
    
    for (int j = 3; j <= 10; j++) {
        if (used[j] == 0) continue;
        for (int _1 = 0; _1 < CH; _1++)
        for (int _4 = _1; _4 < CH; _4++)
        for (int _6 = _4; _6 < CH; _6++)
        for (int _7 = _6; _7 < CH; _7++) {
            auto res = mult(mult(side[j][_1][_4][_6], side[j][_1][_4][_7]), mult(side[j][_1][_6][_7], side[j][_4][_6][_7]));
            if (_1 == _4 && _4 == _6 && _6 == _7) {
                ans = add(ans, res);
            }
            else if ((_1 == _4 && _4 == _6) || (_4 == _6 && _6 == _7)) {
                ans = add(ans, mult(res, 4));
            }
            else if (_1 == _4 && _6 == _7) {
                ans = add(ans, mult(res, 6));
            }
            else if (_1 == _4 || _1 == _6 || _1 == _7 || _4 == _6 || _4 == _7 || _6 == _7) {
                ans = add(ans, mult(res, 12));
            }
            else {
                ans = add(ans, mult(res, 24));
            }
        }
    }
        
    cout << ans << endl;
}

int main() {
    do_not_disturb
    
    int t = 1;
    //~ cin >> t;
    while (t--) {
        solve();
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 503 ms 27044 KB Output is correct
2 Correct 511 ms 27064 KB Output is correct
3 Correct 491 ms 27100 KB Output is correct
4 Correct 503 ms 26968 KB Output is correct
5 Correct 512 ms 26996 KB Output is correct
6 Correct 495 ms 27008 KB Output is correct
7 Correct 485 ms 27200 KB Output is correct
8 Correct 519 ms 26992 KB Output is correct
9 Correct 488 ms 27240 KB Output is correct
10 Correct 516 ms 26980 KB Output is correct
11 Correct 507 ms 27000 KB Output is correct
12 Correct 517 ms 27008 KB Output is correct
13 Correct 500 ms 27040 KB Output is correct
14 Correct 495 ms 27132 KB Output is correct
15 Correct 492 ms 27076 KB Output is correct
16 Correct 524 ms 27068 KB Output is correct
17 Correct 557 ms 26992 KB Output is correct
18 Correct 491 ms 26968 KB Output is correct
19 Correct 494 ms 26980 KB Output is correct
20 Correct 540 ms 27028 KB Output is correct
21 Correct 539 ms 26952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 503 ms 27044 KB Output is correct
2 Correct 511 ms 27064 KB Output is correct
3 Correct 491 ms 27100 KB Output is correct
4 Correct 503 ms 26968 KB Output is correct
5 Correct 512 ms 26996 KB Output is correct
6 Correct 495 ms 27008 KB Output is correct
7 Correct 485 ms 27200 KB Output is correct
8 Correct 519 ms 26992 KB Output is correct
9 Correct 488 ms 27240 KB Output is correct
10 Correct 516 ms 26980 KB Output is correct
11 Correct 507 ms 27000 KB Output is correct
12 Correct 517 ms 27008 KB Output is correct
13 Correct 500 ms 27040 KB Output is correct
14 Correct 495 ms 27132 KB Output is correct
15 Correct 492 ms 27076 KB Output is correct
16 Correct 524 ms 27068 KB Output is correct
17 Correct 557 ms 26992 KB Output is correct
18 Correct 491 ms 26968 KB Output is correct
19 Correct 494 ms 26980 KB Output is correct
20 Correct 540 ms 27028 KB Output is correct
21 Correct 539 ms 26952 KB Output is correct
22 Correct 513 ms 27856 KB Output is correct
23 Correct 500 ms 27872 KB Output is correct
24 Correct 499 ms 27888 KB Output is correct
25 Correct 561 ms 27952 KB Output is correct
26 Correct 488 ms 27880 KB Output is correct
27 Correct 488 ms 27824 KB Output is correct
28 Correct 519 ms 27848 KB Output is correct
29 Correct 480 ms 27884 KB Output is correct
30 Correct 532 ms 28044 KB Output is correct
31 Correct 471 ms 27904 KB Output is correct
32 Correct 505 ms 27896 KB Output is correct
33 Correct 496 ms 27860 KB Output is correct
34 Correct 509 ms 27824 KB Output is correct
35 Correct 500 ms 28036 KB Output is correct
36 Correct 481 ms 27828 KB Output is correct
37 Correct 530 ms 27856 KB Output is correct
38 Correct 523 ms 27872 KB Output is correct
39 Correct 507 ms 27884 KB Output is correct
40 Correct 524 ms 28072 KB Output is correct
41 Correct 511 ms 27796 KB Output is correct
42 Correct 488 ms 27856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 503 ms 27044 KB Output is correct
2 Correct 511 ms 27064 KB Output is correct
3 Correct 491 ms 27100 KB Output is correct
4 Correct 503 ms 26968 KB Output is correct
5 Correct 512 ms 26996 KB Output is correct
6 Correct 495 ms 27008 KB Output is correct
7 Correct 485 ms 27200 KB Output is correct
8 Correct 519 ms 26992 KB Output is correct
9 Correct 488 ms 27240 KB Output is correct
10 Correct 516 ms 26980 KB Output is correct
11 Correct 507 ms 27000 KB Output is correct
12 Correct 517 ms 27008 KB Output is correct
13 Correct 500 ms 27040 KB Output is correct
14 Correct 495 ms 27132 KB Output is correct
15 Correct 492 ms 27076 KB Output is correct
16 Correct 524 ms 27068 KB Output is correct
17 Correct 557 ms 26992 KB Output is correct
18 Correct 491 ms 26968 KB Output is correct
19 Correct 494 ms 26980 KB Output is correct
20 Correct 540 ms 27028 KB Output is correct
21 Correct 539 ms 26952 KB Output is correct
22 Correct 513 ms 27856 KB Output is correct
23 Correct 500 ms 27872 KB Output is correct
24 Correct 499 ms 27888 KB Output is correct
25 Correct 561 ms 27952 KB Output is correct
26 Correct 488 ms 27880 KB Output is correct
27 Correct 488 ms 27824 KB Output is correct
28 Correct 519 ms 27848 KB Output is correct
29 Correct 480 ms 27884 KB Output is correct
30 Correct 532 ms 28044 KB Output is correct
31 Correct 471 ms 27904 KB Output is correct
32 Correct 505 ms 27896 KB Output is correct
33 Correct 496 ms 27860 KB Output is correct
34 Correct 509 ms 27824 KB Output is correct
35 Correct 500 ms 28036 KB Output is correct
36 Correct 481 ms 27828 KB Output is correct
37 Correct 530 ms 27856 KB Output is correct
38 Correct 523 ms 27872 KB Output is correct
39 Correct 507 ms 27884 KB Output is correct
40 Correct 524 ms 28072 KB Output is correct
41 Correct 511 ms 27796 KB Output is correct
42 Correct 488 ms 27856 KB Output is correct
43 Correct 469 ms 28176 KB Output is correct
44 Correct 496 ms 28212 KB Output is correct
45 Correct 518 ms 28228 KB Output is correct
46 Correct 514 ms 28208 KB Output is correct
47 Correct 462 ms 28160 KB Output is correct
48 Correct 505 ms 28244 KB Output is correct
49 Correct 520 ms 28192 KB Output is correct
50 Correct 456 ms 28172 KB Output is correct
51 Correct 507 ms 28172 KB Output is correct
52 Correct 494 ms 28244 KB Output is correct
53 Correct 482 ms 28208 KB Output is correct
54 Correct 471 ms 28192 KB Output is correct
55 Correct 503 ms 28208 KB Output is correct
56 Correct 499 ms 28340 KB Output is correct
57 Correct 479 ms 28216 KB Output is correct
58 Correct 469 ms 28232 KB Output is correct
59 Correct 484 ms 28292 KB Output is correct
60 Correct 455 ms 28168 KB Output is correct
61 Correct 463 ms 28288 KB Output is correct
62 Correct 486 ms 28204 KB Output is correct
63 Correct 539 ms 28200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 503 ms 27044 KB Output is correct
2 Correct 511 ms 27064 KB Output is correct
3 Correct 491 ms 27100 KB Output is correct
4 Correct 503 ms 26968 KB Output is correct
5 Correct 512 ms 26996 KB Output is correct
6 Correct 495 ms 27008 KB Output is correct
7 Correct 485 ms 27200 KB Output is correct
8 Correct 519 ms 26992 KB Output is correct
9 Correct 488 ms 27240 KB Output is correct
10 Correct 516 ms 26980 KB Output is correct
11 Correct 507 ms 27000 KB Output is correct
12 Correct 517 ms 27008 KB Output is correct
13 Correct 500 ms 27040 KB Output is correct
14 Correct 495 ms 27132 KB Output is correct
15 Correct 492 ms 27076 KB Output is correct
16 Correct 524 ms 27068 KB Output is correct
17 Correct 557 ms 26992 KB Output is correct
18 Correct 491 ms 26968 KB Output is correct
19 Correct 494 ms 26980 KB Output is correct
20 Correct 540 ms 27028 KB Output is correct
21 Correct 539 ms 26952 KB Output is correct
22 Correct 513 ms 27856 KB Output is correct
23 Correct 500 ms 27872 KB Output is correct
24 Correct 499 ms 27888 KB Output is correct
25 Correct 561 ms 27952 KB Output is correct
26 Correct 488 ms 27880 KB Output is correct
27 Correct 488 ms 27824 KB Output is correct
28 Correct 519 ms 27848 KB Output is correct
29 Correct 480 ms 27884 KB Output is correct
30 Correct 532 ms 28044 KB Output is correct
31 Correct 471 ms 27904 KB Output is correct
32 Correct 505 ms 27896 KB Output is correct
33 Correct 496 ms 27860 KB Output is correct
34 Correct 509 ms 27824 KB Output is correct
35 Correct 500 ms 28036 KB Output is correct
36 Correct 481 ms 27828 KB Output is correct
37 Correct 530 ms 27856 KB Output is correct
38 Correct 523 ms 27872 KB Output is correct
39 Correct 507 ms 27884 KB Output is correct
40 Correct 524 ms 28072 KB Output is correct
41 Correct 511 ms 27796 KB Output is correct
42 Correct 488 ms 27856 KB Output is correct
43 Correct 469 ms 28176 KB Output is correct
44 Correct 496 ms 28212 KB Output is correct
45 Correct 518 ms 28228 KB Output is correct
46 Correct 514 ms 28208 KB Output is correct
47 Correct 462 ms 28160 KB Output is correct
48 Correct 505 ms 28244 KB Output is correct
49 Correct 520 ms 28192 KB Output is correct
50 Correct 456 ms 28172 KB Output is correct
51 Correct 507 ms 28172 KB Output is correct
52 Correct 494 ms 28244 KB Output is correct
53 Correct 482 ms 28208 KB Output is correct
54 Correct 471 ms 28192 KB Output is correct
55 Correct 503 ms 28208 KB Output is correct
56 Correct 499 ms 28340 KB Output is correct
57 Correct 479 ms 28216 KB Output is correct
58 Correct 469 ms 28232 KB Output is correct
59 Correct 484 ms 28292 KB Output is correct
60 Correct 455 ms 28168 KB Output is correct
61 Correct 463 ms 28288 KB Output is correct
62 Correct 486 ms 28204 KB Output is correct
63 Correct 539 ms 28200 KB Output is correct
64 Correct 465 ms 28572 KB Output is correct
65 Correct 468 ms 29296 KB Output is correct
66 Correct 546 ms 29220 KB Output is correct
67 Correct 520 ms 29200 KB Output is correct
68 Correct 468 ms 29284 KB Output is correct
69 Correct 476 ms 29232 KB Output is correct
70 Correct 466 ms 29320 KB Output is correct
71 Correct 485 ms 29232 KB Output is correct
72 Correct 464 ms 29316 KB Output is correct
73 Correct 468 ms 29228 KB Output is correct
74 Correct 488 ms 29316 KB Output is correct
75 Correct 455 ms 29232 KB Output is correct
76 Correct 486 ms 29212 KB Output is correct
77 Correct 464 ms 29232 KB Output is correct
78 Correct 469 ms 29360 KB Output is correct
79 Correct 483 ms 29276 KB Output is correct
80 Correct 470 ms 29256 KB Output is correct
81 Correct 469 ms 29216 KB Output is correct
82 Correct 468 ms 29232 KB Output is correct
83 Correct 485 ms 29212 KB Output is correct
84 Correct 485 ms 29236 KB Output is correct