Submission #463798

# Submission time Handle Problem Language Result Execution time Memory
463798 2021-08-11T19:01:14 Z JovanB Cubeword (CEOI19_cubeword) C++17
100 / 100
402 ms 17628 KB
#include <bits/stdc++.h>
/*#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")*/
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
const int MOD = 998244353;
 
int add(int a, int b){
    return (a+b)%MOD;
}
 
int mul(int a, int b){
    return ((ll)a * b)%MOD;
}
 
int br[11][70][70];
int dp[70][70][70];
 
int koji(char c){
    if('a' <= c && c <= 'z') return c-'a';
    if('A' <= c && c <= 'Z') return 26 + (c-'A');
    return 52 + (c-'0');
}
 
int perm(int a, int b, int c, int d){
    if(a == b && b == c && c == d) return 1;
    if(a == b && b == c) return 4;
    if(b == c && c == d) return 4;
    if(a == b && c == d) return 6;
    if(a == b) return 12;
    if(b == c) return 12;
    if(c == d) return 12;
    return 24;
}
 
int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;
 
    int n;
    cin >> n;
    set <string> q;
    while(n--){
        string s;
        cin >> s;
        q.insert(s);
        reverse(s.begin(), s.end());
        q.insert(s);
    }
    for(auto s : q){
        br[s.size()][koji(s[0])][koji(s[s.size()-1])]++;
    }
    int res = 0;
    for(int sz=3; sz<=10; sz++){
        for(int i=0; i<62; i++){
            for(int j=i; j<62; j++){
                for(int k=j; k<62; k++){
                    dp[i][j][k] = 0;
                    for(int l=0; l<62; l++){
                        dp[i][j][k] = add(dp[i][j][k], mul(br[sz][i][l], mul(br[sz][j][l], br[sz][k][l])));
                    }
                }
            }
        }
        for(int i=0; i<62; i++){
            for(int j=i; j<62; j++){
                for(int k=j; k<62; k++){
                    for(int l=k; l<62; l++){
                        res = add(res, mul(perm(i, j, k, l), mul(dp[i][j][k], mul(dp[i][j][l], mul(dp[i][k][l], dp[j][k][l])))));
                    }
                }
            }
        }
    }
    cout << res;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 376 ms 16472 KB Output is correct
2 Correct 379 ms 16448 KB Output is correct
3 Correct 381 ms 16512 KB Output is correct
4 Correct 372 ms 16464 KB Output is correct
5 Correct 369 ms 16576 KB Output is correct
6 Correct 361 ms 16500 KB Output is correct
7 Correct 369 ms 16460 KB Output is correct
8 Correct 357 ms 16460 KB Output is correct
9 Correct 360 ms 16448 KB Output is correct
10 Correct 360 ms 16464 KB Output is correct
11 Correct 370 ms 16540 KB Output is correct
12 Correct 357 ms 16560 KB Output is correct
13 Correct 376 ms 16456 KB Output is correct
14 Correct 360 ms 16400 KB Output is correct
15 Correct 360 ms 16580 KB Output is correct
16 Correct 402 ms 16444 KB Output is correct
17 Correct 370 ms 16460 KB Output is correct
18 Correct 365 ms 16488 KB Output is correct
19 Correct 371 ms 16456 KB Output is correct
20 Correct 370 ms 16452 KB Output is correct
21 Correct 364 ms 16400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 376 ms 16472 KB Output is correct
2 Correct 379 ms 16448 KB Output is correct
3 Correct 381 ms 16512 KB Output is correct
4 Correct 372 ms 16464 KB Output is correct
5 Correct 369 ms 16576 KB Output is correct
6 Correct 361 ms 16500 KB Output is correct
7 Correct 369 ms 16460 KB Output is correct
8 Correct 357 ms 16460 KB Output is correct
9 Correct 360 ms 16448 KB Output is correct
10 Correct 360 ms 16464 KB Output is correct
11 Correct 370 ms 16540 KB Output is correct
12 Correct 357 ms 16560 KB Output is correct
13 Correct 376 ms 16456 KB Output is correct
14 Correct 360 ms 16400 KB Output is correct
15 Correct 360 ms 16580 KB Output is correct
16 Correct 402 ms 16444 KB Output is correct
17 Correct 370 ms 16460 KB Output is correct
18 Correct 365 ms 16488 KB Output is correct
19 Correct 371 ms 16456 KB Output is correct
20 Correct 370 ms 16452 KB Output is correct
21 Correct 364 ms 16400 KB Output is correct
22 Correct 365 ms 17064 KB Output is correct
23 Correct 371 ms 17052 KB Output is correct
24 Correct 363 ms 16976 KB Output is correct
25 Correct 364 ms 17044 KB Output is correct
26 Correct 376 ms 16964 KB Output is correct
27 Correct 377 ms 17152 KB Output is correct
28 Correct 366 ms 17012 KB Output is correct
29 Correct 369 ms 17104 KB Output is correct
30 Correct 392 ms 17044 KB Output is correct
31 Correct 380 ms 17048 KB Output is correct
32 Correct 386 ms 17036 KB Output is correct
33 Correct 376 ms 17040 KB Output is correct
34 Correct 395 ms 16952 KB Output is correct
35 Correct 376 ms 16996 KB Output is correct
36 Correct 365 ms 17056 KB Output is correct
37 Correct 378 ms 17012 KB Output is correct
38 Correct 376 ms 17056 KB Output is correct
39 Correct 363 ms 16992 KB Output is correct
40 Correct 371 ms 16988 KB Output is correct
41 Correct 359 ms 17156 KB Output is correct
42 Correct 372 ms 17088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 376 ms 16472 KB Output is correct
2 Correct 379 ms 16448 KB Output is correct
3 Correct 381 ms 16512 KB Output is correct
4 Correct 372 ms 16464 KB Output is correct
5 Correct 369 ms 16576 KB Output is correct
6 Correct 361 ms 16500 KB Output is correct
7 Correct 369 ms 16460 KB Output is correct
8 Correct 357 ms 16460 KB Output is correct
9 Correct 360 ms 16448 KB Output is correct
10 Correct 360 ms 16464 KB Output is correct
11 Correct 370 ms 16540 KB Output is correct
12 Correct 357 ms 16560 KB Output is correct
13 Correct 376 ms 16456 KB Output is correct
14 Correct 360 ms 16400 KB Output is correct
15 Correct 360 ms 16580 KB Output is correct
16 Correct 402 ms 16444 KB Output is correct
17 Correct 370 ms 16460 KB Output is correct
18 Correct 365 ms 16488 KB Output is correct
19 Correct 371 ms 16456 KB Output is correct
20 Correct 370 ms 16452 KB Output is correct
21 Correct 364 ms 16400 KB Output is correct
22 Correct 365 ms 17064 KB Output is correct
23 Correct 371 ms 17052 KB Output is correct
24 Correct 363 ms 16976 KB Output is correct
25 Correct 364 ms 17044 KB Output is correct
26 Correct 376 ms 16964 KB Output is correct
27 Correct 377 ms 17152 KB Output is correct
28 Correct 366 ms 17012 KB Output is correct
29 Correct 369 ms 17104 KB Output is correct
30 Correct 392 ms 17044 KB Output is correct
31 Correct 380 ms 17048 KB Output is correct
32 Correct 386 ms 17036 KB Output is correct
33 Correct 376 ms 17040 KB Output is correct
34 Correct 395 ms 16952 KB Output is correct
35 Correct 376 ms 16996 KB Output is correct
36 Correct 365 ms 17056 KB Output is correct
37 Correct 378 ms 17012 KB Output is correct
38 Correct 376 ms 17056 KB Output is correct
39 Correct 363 ms 16992 KB Output is correct
40 Correct 371 ms 16988 KB Output is correct
41 Correct 359 ms 17156 KB Output is correct
42 Correct 372 ms 17088 KB Output is correct
43 Correct 365 ms 17220 KB Output is correct
44 Correct 378 ms 17244 KB Output is correct
45 Correct 367 ms 17348 KB Output is correct
46 Correct 366 ms 17284 KB Output is correct
47 Correct 360 ms 17348 KB Output is correct
48 Correct 371 ms 17220 KB Output is correct
49 Correct 374 ms 17204 KB Output is correct
50 Correct 363 ms 17296 KB Output is correct
51 Correct 363 ms 17168 KB Output is correct
52 Correct 365 ms 17228 KB Output is correct
53 Correct 361 ms 17300 KB Output is correct
54 Correct 363 ms 17252 KB Output is correct
55 Correct 369 ms 17292 KB Output is correct
56 Correct 375 ms 17280 KB Output is correct
57 Correct 378 ms 17188 KB Output is correct
58 Correct 374 ms 17236 KB Output is correct
59 Correct 364 ms 17288 KB Output is correct
60 Correct 361 ms 17284 KB Output is correct
61 Correct 368 ms 17344 KB Output is correct
62 Correct 366 ms 17280 KB Output is correct
63 Correct 366 ms 17296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 376 ms 16472 KB Output is correct
2 Correct 379 ms 16448 KB Output is correct
3 Correct 381 ms 16512 KB Output is correct
4 Correct 372 ms 16464 KB Output is correct
5 Correct 369 ms 16576 KB Output is correct
6 Correct 361 ms 16500 KB Output is correct
7 Correct 369 ms 16460 KB Output is correct
8 Correct 357 ms 16460 KB Output is correct
9 Correct 360 ms 16448 KB Output is correct
10 Correct 360 ms 16464 KB Output is correct
11 Correct 370 ms 16540 KB Output is correct
12 Correct 357 ms 16560 KB Output is correct
13 Correct 376 ms 16456 KB Output is correct
14 Correct 360 ms 16400 KB Output is correct
15 Correct 360 ms 16580 KB Output is correct
16 Correct 402 ms 16444 KB Output is correct
17 Correct 370 ms 16460 KB Output is correct
18 Correct 365 ms 16488 KB Output is correct
19 Correct 371 ms 16456 KB Output is correct
20 Correct 370 ms 16452 KB Output is correct
21 Correct 364 ms 16400 KB Output is correct
22 Correct 365 ms 17064 KB Output is correct
23 Correct 371 ms 17052 KB Output is correct
24 Correct 363 ms 16976 KB Output is correct
25 Correct 364 ms 17044 KB Output is correct
26 Correct 376 ms 16964 KB Output is correct
27 Correct 377 ms 17152 KB Output is correct
28 Correct 366 ms 17012 KB Output is correct
29 Correct 369 ms 17104 KB Output is correct
30 Correct 392 ms 17044 KB Output is correct
31 Correct 380 ms 17048 KB Output is correct
32 Correct 386 ms 17036 KB Output is correct
33 Correct 376 ms 17040 KB Output is correct
34 Correct 395 ms 16952 KB Output is correct
35 Correct 376 ms 16996 KB Output is correct
36 Correct 365 ms 17056 KB Output is correct
37 Correct 378 ms 17012 KB Output is correct
38 Correct 376 ms 17056 KB Output is correct
39 Correct 363 ms 16992 KB Output is correct
40 Correct 371 ms 16988 KB Output is correct
41 Correct 359 ms 17156 KB Output is correct
42 Correct 372 ms 17088 KB Output is correct
43 Correct 365 ms 17220 KB Output is correct
44 Correct 378 ms 17244 KB Output is correct
45 Correct 367 ms 17348 KB Output is correct
46 Correct 366 ms 17284 KB Output is correct
47 Correct 360 ms 17348 KB Output is correct
48 Correct 371 ms 17220 KB Output is correct
49 Correct 374 ms 17204 KB Output is correct
50 Correct 363 ms 17296 KB Output is correct
51 Correct 363 ms 17168 KB Output is correct
52 Correct 365 ms 17228 KB Output is correct
53 Correct 361 ms 17300 KB Output is correct
54 Correct 363 ms 17252 KB Output is correct
55 Correct 369 ms 17292 KB Output is correct
56 Correct 375 ms 17280 KB Output is correct
57 Correct 378 ms 17188 KB Output is correct
58 Correct 374 ms 17236 KB Output is correct
59 Correct 364 ms 17288 KB Output is correct
60 Correct 361 ms 17284 KB Output is correct
61 Correct 368 ms 17344 KB Output is correct
62 Correct 366 ms 17280 KB Output is correct
63 Correct 366 ms 17296 KB Output is correct
64 Correct 370 ms 17432 KB Output is correct
65 Correct 372 ms 17572 KB Output is correct
66 Correct 363 ms 17440 KB Output is correct
67 Correct 365 ms 17544 KB Output is correct
68 Correct 373 ms 17500 KB Output is correct
69 Correct 359 ms 17540 KB Output is correct
70 Correct 360 ms 17552 KB Output is correct
71 Correct 361 ms 17476 KB Output is correct
72 Correct 376 ms 17628 KB Output is correct
73 Correct 365 ms 17468 KB Output is correct
74 Correct 379 ms 17600 KB Output is correct
75 Correct 369 ms 17548 KB Output is correct
76 Correct 365 ms 17604 KB Output is correct
77 Correct 363 ms 17472 KB Output is correct
78 Correct 382 ms 17604 KB Output is correct
79 Correct 367 ms 17476 KB Output is correct
80 Correct 363 ms 17548 KB Output is correct
81 Correct 366 ms 17560 KB Output is correct
82 Correct 363 ms 17548 KB Output is correct
83 Correct 383 ms 17476 KB Output is correct
84 Correct 362 ms 17528 KB Output is correct