Submission #1004650

# Submission time Handle Problem Language Result Execution time Memory
1004650 2024-06-21T11:23:26 Z vjudge1 Cubeword (CEOI19_cubeword) C++17
84 / 100
361 ms 12704 KB
#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;
const int MK = 32;
using vi = vector<int>;
using ll = long long;

int id2(char c) {
    if(c >= 'a' && c <= 'z') return c - 'a';
    if(c >= 'A' && c <= 'Z') return c - 'A' + 26; 
    return c - '0' + 52;
}
int id(char c) {
    if(c >= 'a' && c <= 'p') return c - 'a';
    if(c >= 'A' && c <= 'P') return c - 'A' + 16; 
}

int solve(vector<string> V) {
    if(V.empty()) return 0;
    set<string> S;
    for (auto it : V) {
        S.insert(it);
        string s2 = it;
        reverse(s2.begin(), s2.end());
        S.insert(s2);
    }
    array<array<int, MK>, MK> Fr;
    for (int i = 0; i < MK; ++i)
        for (int j = 0; j < MK; ++j)
            Fr[i][j] = 0;
    for (auto it : S) {
        int a = id(it[0]), b= id(it.back());
        ++Fr[a][b];
    }

    array<array<array<int, MK>, MK>, MK> u, v;
    for(int i = 0; i < MK; ++i)
        for(int j = 0; j < MK; ++j)
            for(int k = 0; k < MK; ++k)
                u[i][j][k] = v[i][j][k] = 0;
    for(int i = 0; i < MK; ++i)
        for(int j = 0; j < MK; ++j)
            for(int k = 0; k < MK; ++k) {
                for(int w = 0; w < MK; ++w) {
                    v[i][j][k] = (v[i][j][k] 
                    + 1ll * Fr[i][w] * Fr[j][w] % MOD * Fr[k][w] % MOD) % MOD;
                }
            }
    for(int i = 0; i < MK; ++i)
        for(int j = 0; j < MK; ++j)
            for(int k = 0; k < MK; ++k)
                u[i][j][k] = 1ll * Fr[i][k] * Fr[j][k] % MOD;
    ll re = 0;
    for(int i = 0; i < MK; ++i)
        for(int j = 0; j < MK; ++j)
            for(int k = 0; k < MK; ++k)
                for(int w = 0; w < MK; ++w) {
                    /// (v[i,j] \cdot u[k, w]) * (v[k, w] \cdot u[i, j])
                    ll v1 = 0, v2 = 0;
                    for(int a = 0; a < MK; ++a)
                        v1 = (v1 + 1ll * v[i][j][a] * u[k][w][a]);
                    v1 %= MOD;
                    ll cre = v1 * v1 % MOD * Fr[i][k] % MOD * Fr[j][w] % MOD;
                    re = (re + cre) % MOD;
                }
    return (int)re;
}

int main() {
    const int MLEN = 10;
    vector<vector<string> > V(MLEN + 1);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        V[s.size()].push_back(s);
    }
    int re = 0;
    for (int i = 0; i <= MLEN; ++i) {
        re = (re + solve(V[i])) % MOD;
    }
    cout << re << "\n";
    return 0;
}

Compilation message

cubeword.cpp: In function 'int solve(std::vector<std::__cxx11::basic_string<char> >)':
cubeword.cpp:61:32: warning: unused variable 'v2' [-Wunused-variable]
   61 |                     ll v1 = 0, v2 = 0;
      |                                ^~
cubeword.cpp: In function 'int id(char)':
cubeword.cpp:18:1: warning: control reaches end of non-void function [-Wreturn-type]
   18 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 337 ms 8184 KB Output is correct
2 Correct 318 ms 8356 KB Output is correct
3 Correct 338 ms 8144 KB Output is correct
4 Correct 331 ms 8156 KB Output is correct
5 Correct 308 ms 8132 KB Output is correct
6 Correct 342 ms 8224 KB Output is correct
7 Correct 308 ms 8124 KB Output is correct
8 Correct 337 ms 8316 KB Output is correct
9 Correct 330 ms 8276 KB Output is correct
10 Correct 327 ms 8316 KB Output is correct
11 Correct 310 ms 8164 KB Output is correct
12 Correct 322 ms 8164 KB Output is correct
13 Correct 321 ms 8232 KB Output is correct
14 Correct 313 ms 8260 KB Output is correct
15 Correct 323 ms 8232 KB Output is correct
16 Correct 306 ms 8132 KB Output is correct
17 Correct 344 ms 8128 KB Output is correct
18 Correct 322 ms 8116 KB Output is correct
19 Correct 352 ms 8152 KB Output is correct
20 Correct 325 ms 8092 KB Output is correct
21 Correct 333 ms 8264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 337 ms 8184 KB Output is correct
2 Correct 318 ms 8356 KB Output is correct
3 Correct 338 ms 8144 KB Output is correct
4 Correct 331 ms 8156 KB Output is correct
5 Correct 308 ms 8132 KB Output is correct
6 Correct 342 ms 8224 KB Output is correct
7 Correct 308 ms 8124 KB Output is correct
8 Correct 337 ms 8316 KB Output is correct
9 Correct 330 ms 8276 KB Output is correct
10 Correct 327 ms 8316 KB Output is correct
11 Correct 310 ms 8164 KB Output is correct
12 Correct 322 ms 8164 KB Output is correct
13 Correct 321 ms 8232 KB Output is correct
14 Correct 313 ms 8260 KB Output is correct
15 Correct 323 ms 8232 KB Output is correct
16 Correct 306 ms 8132 KB Output is correct
17 Correct 344 ms 8128 KB Output is correct
18 Correct 322 ms 8116 KB Output is correct
19 Correct 352 ms 8152 KB Output is correct
20 Correct 325 ms 8092 KB Output is correct
21 Correct 333 ms 8264 KB Output is correct
22 Correct 322 ms 7124 KB Output is correct
23 Correct 346 ms 7192 KB Output is correct
24 Correct 310 ms 7132 KB Output is correct
25 Correct 299 ms 7184 KB Output is correct
26 Correct 335 ms 7192 KB Output is correct
27 Correct 361 ms 7176 KB Output is correct
28 Correct 311 ms 7188 KB Output is correct
29 Correct 306 ms 7064 KB Output is correct
30 Correct 341 ms 7120 KB Output is correct
31 Correct 305 ms 7184 KB Output is correct
32 Correct 313 ms 7180 KB Output is correct
33 Correct 309 ms 7216 KB Output is correct
34 Correct 309 ms 7172 KB Output is correct
35 Correct 305 ms 7116 KB Output is correct
36 Correct 316 ms 7132 KB Output is correct
37 Correct 307 ms 7156 KB Output is correct
38 Correct 297 ms 7228 KB Output is correct
39 Correct 315 ms 7136 KB Output is correct
40 Correct 315 ms 7004 KB Output is correct
41 Correct 307 ms 7072 KB Output is correct
42 Correct 301 ms 7200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 337 ms 8184 KB Output is correct
2 Correct 318 ms 8356 KB Output is correct
3 Correct 338 ms 8144 KB Output is correct
4 Correct 331 ms 8156 KB Output is correct
5 Correct 308 ms 8132 KB Output is correct
6 Correct 342 ms 8224 KB Output is correct
7 Correct 308 ms 8124 KB Output is correct
8 Correct 337 ms 8316 KB Output is correct
9 Correct 330 ms 8276 KB Output is correct
10 Correct 327 ms 8316 KB Output is correct
11 Correct 310 ms 8164 KB Output is correct
12 Correct 322 ms 8164 KB Output is correct
13 Correct 321 ms 8232 KB Output is correct
14 Correct 313 ms 8260 KB Output is correct
15 Correct 323 ms 8232 KB Output is correct
16 Correct 306 ms 8132 KB Output is correct
17 Correct 344 ms 8128 KB Output is correct
18 Correct 322 ms 8116 KB Output is correct
19 Correct 352 ms 8152 KB Output is correct
20 Correct 325 ms 8092 KB Output is correct
21 Correct 333 ms 8264 KB Output is correct
22 Correct 322 ms 7124 KB Output is correct
23 Correct 346 ms 7192 KB Output is correct
24 Correct 310 ms 7132 KB Output is correct
25 Correct 299 ms 7184 KB Output is correct
26 Correct 335 ms 7192 KB Output is correct
27 Correct 361 ms 7176 KB Output is correct
28 Correct 311 ms 7188 KB Output is correct
29 Correct 306 ms 7064 KB Output is correct
30 Correct 341 ms 7120 KB Output is correct
31 Correct 305 ms 7184 KB Output is correct
32 Correct 313 ms 7180 KB Output is correct
33 Correct 309 ms 7216 KB Output is correct
34 Correct 309 ms 7172 KB Output is correct
35 Correct 305 ms 7116 KB Output is correct
36 Correct 316 ms 7132 KB Output is correct
37 Correct 307 ms 7156 KB Output is correct
38 Correct 297 ms 7228 KB Output is correct
39 Correct 315 ms 7136 KB Output is correct
40 Correct 315 ms 7004 KB Output is correct
41 Correct 307 ms 7072 KB Output is correct
42 Correct 301 ms 7200 KB Output is correct
43 Correct 302 ms 7120 KB Output is correct
44 Correct 304 ms 7008 KB Output is correct
45 Correct 314 ms 6872 KB Output is correct
46 Correct 336 ms 6820 KB Output is correct
47 Correct 323 ms 6888 KB Output is correct
48 Correct 352 ms 6952 KB Output is correct
49 Correct 351 ms 7148 KB Output is correct
50 Correct 350 ms 7004 KB Output is correct
51 Correct 331 ms 6740 KB Output is correct
52 Correct 333 ms 7128 KB Output is correct
53 Correct 333 ms 6868 KB Output is correct
54 Correct 330 ms 7008 KB Output is correct
55 Correct 330 ms 6820 KB Output is correct
56 Correct 320 ms 7100 KB Output is correct
57 Correct 330 ms 6868 KB Output is correct
58 Correct 312 ms 6812 KB Output is correct
59 Correct 308 ms 6868 KB Output is correct
60 Correct 310 ms 6940 KB Output is correct
61 Correct 321 ms 6944 KB Output is correct
62 Correct 315 ms 6988 KB Output is correct
63 Correct 306 ms 6808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 337 ms 8184 KB Output is correct
2 Correct 318 ms 8356 KB Output is correct
3 Correct 338 ms 8144 KB Output is correct
4 Correct 331 ms 8156 KB Output is correct
5 Correct 308 ms 8132 KB Output is correct
6 Correct 342 ms 8224 KB Output is correct
7 Correct 308 ms 8124 KB Output is correct
8 Correct 337 ms 8316 KB Output is correct
9 Correct 330 ms 8276 KB Output is correct
10 Correct 327 ms 8316 KB Output is correct
11 Correct 310 ms 8164 KB Output is correct
12 Correct 322 ms 8164 KB Output is correct
13 Correct 321 ms 8232 KB Output is correct
14 Correct 313 ms 8260 KB Output is correct
15 Correct 323 ms 8232 KB Output is correct
16 Correct 306 ms 8132 KB Output is correct
17 Correct 344 ms 8128 KB Output is correct
18 Correct 322 ms 8116 KB Output is correct
19 Correct 352 ms 8152 KB Output is correct
20 Correct 325 ms 8092 KB Output is correct
21 Correct 333 ms 8264 KB Output is correct
22 Correct 322 ms 7124 KB Output is correct
23 Correct 346 ms 7192 KB Output is correct
24 Correct 310 ms 7132 KB Output is correct
25 Correct 299 ms 7184 KB Output is correct
26 Correct 335 ms 7192 KB Output is correct
27 Correct 361 ms 7176 KB Output is correct
28 Correct 311 ms 7188 KB Output is correct
29 Correct 306 ms 7064 KB Output is correct
30 Correct 341 ms 7120 KB Output is correct
31 Correct 305 ms 7184 KB Output is correct
32 Correct 313 ms 7180 KB Output is correct
33 Correct 309 ms 7216 KB Output is correct
34 Correct 309 ms 7172 KB Output is correct
35 Correct 305 ms 7116 KB Output is correct
36 Correct 316 ms 7132 KB Output is correct
37 Correct 307 ms 7156 KB Output is correct
38 Correct 297 ms 7228 KB Output is correct
39 Correct 315 ms 7136 KB Output is correct
40 Correct 315 ms 7004 KB Output is correct
41 Correct 307 ms 7072 KB Output is correct
42 Correct 301 ms 7200 KB Output is correct
43 Correct 302 ms 7120 KB Output is correct
44 Correct 304 ms 7008 KB Output is correct
45 Correct 314 ms 6872 KB Output is correct
46 Correct 336 ms 6820 KB Output is correct
47 Correct 323 ms 6888 KB Output is correct
48 Correct 352 ms 6952 KB Output is correct
49 Correct 351 ms 7148 KB Output is correct
50 Correct 350 ms 7004 KB Output is correct
51 Correct 331 ms 6740 KB Output is correct
52 Correct 333 ms 7128 KB Output is correct
53 Correct 333 ms 6868 KB Output is correct
54 Correct 330 ms 7008 KB Output is correct
55 Correct 330 ms 6820 KB Output is correct
56 Correct 320 ms 7100 KB Output is correct
57 Correct 330 ms 6868 KB Output is correct
58 Correct 312 ms 6812 KB Output is correct
59 Correct 308 ms 6868 KB Output is correct
60 Correct 310 ms 6940 KB Output is correct
61 Correct 321 ms 6944 KB Output is correct
62 Correct 315 ms 6988 KB Output is correct
63 Correct 306 ms 6808 KB Output is correct
64 Runtime error 25 ms 12704 KB Execution killed with signal 11
65 Halted 0 ms 0 KB -