#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int AL = 52;
const int LEN = 11;
const int MOD = 998244353;
int cnt[AL][AL][LEN];
bool is_palin(string t){
for(int i = 0 ; i < t.size() ; i ++ ){
if(t[i] != t[(int)t.size() - 1 - i]){
return false;
}
}
return true;
}
int D[AL][AL][AL];
int mlt(int a, int b){
return (a * 1ll * b) % MOD;
}
void add(int &a, int b){
a = (a + b) % MOD;
}
int getid(char f){
if(f >= 'a' && f <= 'z') return f - 'a';
else if(f >= 'A' && f <= 'Z') return 26 + (f - 'A');
return 52 + f - '0';
}
map<string, bool> dict;
int perm[AL][AL][AL][AL];
int calc(vector<int> q){
sort(q.begin(), q.end());
int cnt = 0;
do{
cnt ++ ;
}while(next_permutation(q.begin(), q.end()));
return cnt;
}
int main(){
fastIO;
int n;
cin >> n;
string t;
int m;
int fa, fb;
for(int i = 0 ; i < n; i ++ ){
cin >> t;
m = t.size();
if(dict.count(t)) continue;
fa=getid(t[0]);
fb=getid(t.back());
cnt[fa][fb][m]++;
if(!is_palin(t)) cnt[fb][fa][m]++;
dict[t]=true;
reverse(t.begin(), t.end());
dict[t]=true;
}
for(int i = 0 ; i < AL; i ++ ){
for(int j = i ; j < AL; j ++ ){
for(int p = j ; p < AL; p ++ ){
for(int t = p ; t < AL; t ++ ){
perm[i][j][p][t]=calc({i,j,p,t});
}
}
}
}
int sol = 0;
for(int len = 3; len <= 10; len ++ ){
for(int i = 0 ; i < AL; i ++ ){
for(int j = i ; j < AL; j ++ ){
for(int k = j ; k < AL; k ++ ){
D[i][j][k]=0;
for(int q = 0; q < AL; q ++ ){
add(D[i][j][k],mlt(mlt(cnt[i][q][len],cnt[j][q][len]),cnt[k][q][len]));
}
}
}
}
for(int a = 0; a < AL; a ++ ){
for(int d = a ; d < AL; d ++ ){
for(int e = d; e < AL; e ++ ){
if(D[a][d][e] == 0) continue;
for(int h = e; h < AL; h ++ ){
add(sol,mlt(perm[a][d][e][h],mlt(mlt(D[a][d][e],D[a][d][h]),mlt(D[d][e][h],D[a][e][h]))));
}
}
}
}
}
cout << sol << "\n";
return 0;
}
Compilation message
cubeword.cpp: In function 'bool is_palin(std::string)':
cubeword.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i = 0 ; i < t.size() ; i ++ ){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
393 ms |
26348 KB |
Output is correct |
2 |
Correct |
376 ms |
26348 KB |
Output is correct |
3 |
Correct |
364 ms |
26220 KB |
Output is correct |
4 |
Correct |
374 ms |
26220 KB |
Output is correct |
5 |
Correct |
379 ms |
26220 KB |
Output is correct |
6 |
Correct |
387 ms |
26344 KB |
Output is correct |
7 |
Correct |
369 ms |
26348 KB |
Output is correct |
8 |
Correct |
375 ms |
26348 KB |
Output is correct |
9 |
Correct |
374 ms |
26220 KB |
Output is correct |
10 |
Correct |
420 ms |
26292 KB |
Output is correct |
11 |
Correct |
369 ms |
26220 KB |
Output is correct |
12 |
Correct |
397 ms |
26348 KB |
Output is correct |
13 |
Correct |
400 ms |
26348 KB |
Output is correct |
14 |
Correct |
393 ms |
26276 KB |
Output is correct |
15 |
Correct |
373 ms |
26348 KB |
Output is correct |
16 |
Correct |
458 ms |
26220 KB |
Output is correct |
17 |
Correct |
382 ms |
26348 KB |
Output is correct |
18 |
Correct |
413 ms |
26220 KB |
Output is correct |
19 |
Correct |
381 ms |
26220 KB |
Output is correct |
20 |
Correct |
369 ms |
26220 KB |
Output is correct |
21 |
Correct |
374 ms |
26348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
393 ms |
26348 KB |
Output is correct |
2 |
Correct |
376 ms |
26348 KB |
Output is correct |
3 |
Correct |
364 ms |
26220 KB |
Output is correct |
4 |
Correct |
374 ms |
26220 KB |
Output is correct |
5 |
Correct |
379 ms |
26220 KB |
Output is correct |
6 |
Correct |
387 ms |
26344 KB |
Output is correct |
7 |
Correct |
369 ms |
26348 KB |
Output is correct |
8 |
Correct |
375 ms |
26348 KB |
Output is correct |
9 |
Correct |
374 ms |
26220 KB |
Output is correct |
10 |
Correct |
420 ms |
26292 KB |
Output is correct |
11 |
Correct |
369 ms |
26220 KB |
Output is correct |
12 |
Correct |
397 ms |
26348 KB |
Output is correct |
13 |
Correct |
400 ms |
26348 KB |
Output is correct |
14 |
Correct |
393 ms |
26276 KB |
Output is correct |
15 |
Correct |
373 ms |
26348 KB |
Output is correct |
16 |
Correct |
458 ms |
26220 KB |
Output is correct |
17 |
Correct |
382 ms |
26348 KB |
Output is correct |
18 |
Correct |
413 ms |
26220 KB |
Output is correct |
19 |
Correct |
381 ms |
26220 KB |
Output is correct |
20 |
Correct |
369 ms |
26220 KB |
Output is correct |
21 |
Correct |
374 ms |
26348 KB |
Output is correct |
22 |
Correct |
376 ms |
26860 KB |
Output is correct |
23 |
Correct |
378 ms |
26988 KB |
Output is correct |
24 |
Correct |
372 ms |
26988 KB |
Output is correct |
25 |
Correct |
390 ms |
26860 KB |
Output is correct |
26 |
Correct |
376 ms |
26988 KB |
Output is correct |
27 |
Correct |
376 ms |
26888 KB |
Output is correct |
28 |
Correct |
381 ms |
27116 KB |
Output is correct |
29 |
Correct |
385 ms |
26860 KB |
Output is correct |
30 |
Correct |
377 ms |
26988 KB |
Output is correct |
31 |
Correct |
372 ms |
26860 KB |
Output is correct |
32 |
Correct |
412 ms |
26856 KB |
Output is correct |
33 |
Correct |
377 ms |
26860 KB |
Output is correct |
34 |
Correct |
387 ms |
27136 KB |
Output is correct |
35 |
Correct |
378 ms |
26988 KB |
Output is correct |
36 |
Correct |
381 ms |
27040 KB |
Output is correct |
37 |
Correct |
387 ms |
26920 KB |
Output is correct |
38 |
Correct |
375 ms |
27116 KB |
Output is correct |
39 |
Correct |
376 ms |
26860 KB |
Output is correct |
40 |
Correct |
387 ms |
26860 KB |
Output is correct |
41 |
Correct |
374 ms |
26988 KB |
Output is correct |
42 |
Correct |
368 ms |
26860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
393 ms |
26348 KB |
Output is correct |
2 |
Correct |
376 ms |
26348 KB |
Output is correct |
3 |
Correct |
364 ms |
26220 KB |
Output is correct |
4 |
Correct |
374 ms |
26220 KB |
Output is correct |
5 |
Correct |
379 ms |
26220 KB |
Output is correct |
6 |
Correct |
387 ms |
26344 KB |
Output is correct |
7 |
Correct |
369 ms |
26348 KB |
Output is correct |
8 |
Correct |
375 ms |
26348 KB |
Output is correct |
9 |
Correct |
374 ms |
26220 KB |
Output is correct |
10 |
Correct |
420 ms |
26292 KB |
Output is correct |
11 |
Correct |
369 ms |
26220 KB |
Output is correct |
12 |
Correct |
397 ms |
26348 KB |
Output is correct |
13 |
Correct |
400 ms |
26348 KB |
Output is correct |
14 |
Correct |
393 ms |
26276 KB |
Output is correct |
15 |
Correct |
373 ms |
26348 KB |
Output is correct |
16 |
Correct |
458 ms |
26220 KB |
Output is correct |
17 |
Correct |
382 ms |
26348 KB |
Output is correct |
18 |
Correct |
413 ms |
26220 KB |
Output is correct |
19 |
Correct |
381 ms |
26220 KB |
Output is correct |
20 |
Correct |
369 ms |
26220 KB |
Output is correct |
21 |
Correct |
374 ms |
26348 KB |
Output is correct |
22 |
Correct |
376 ms |
26860 KB |
Output is correct |
23 |
Correct |
378 ms |
26988 KB |
Output is correct |
24 |
Correct |
372 ms |
26988 KB |
Output is correct |
25 |
Correct |
390 ms |
26860 KB |
Output is correct |
26 |
Correct |
376 ms |
26988 KB |
Output is correct |
27 |
Correct |
376 ms |
26888 KB |
Output is correct |
28 |
Correct |
381 ms |
27116 KB |
Output is correct |
29 |
Correct |
385 ms |
26860 KB |
Output is correct |
30 |
Correct |
377 ms |
26988 KB |
Output is correct |
31 |
Correct |
372 ms |
26860 KB |
Output is correct |
32 |
Correct |
412 ms |
26856 KB |
Output is correct |
33 |
Correct |
377 ms |
26860 KB |
Output is correct |
34 |
Correct |
387 ms |
27136 KB |
Output is correct |
35 |
Correct |
378 ms |
26988 KB |
Output is correct |
36 |
Correct |
381 ms |
27040 KB |
Output is correct |
37 |
Correct |
387 ms |
26920 KB |
Output is correct |
38 |
Correct |
375 ms |
27116 KB |
Output is correct |
39 |
Correct |
376 ms |
26860 KB |
Output is correct |
40 |
Correct |
387 ms |
26860 KB |
Output is correct |
41 |
Correct |
374 ms |
26988 KB |
Output is correct |
42 |
Correct |
368 ms |
26860 KB |
Output is correct |
43 |
Correct |
399 ms |
27064 KB |
Output is correct |
44 |
Correct |
393 ms |
27244 KB |
Output is correct |
45 |
Correct |
374 ms |
27116 KB |
Output is correct |
46 |
Correct |
383 ms |
27244 KB |
Output is correct |
47 |
Correct |
380 ms |
27116 KB |
Output is correct |
48 |
Correct |
376 ms |
27116 KB |
Output is correct |
49 |
Correct |
384 ms |
27116 KB |
Output is correct |
50 |
Correct |
385 ms |
27244 KB |
Output is correct |
51 |
Correct |
382 ms |
27116 KB |
Output is correct |
52 |
Correct |
398 ms |
27116 KB |
Output is correct |
53 |
Correct |
379 ms |
27116 KB |
Output is correct |
54 |
Correct |
397 ms |
27244 KB |
Output is correct |
55 |
Correct |
384 ms |
27116 KB |
Output is correct |
56 |
Correct |
383 ms |
27116 KB |
Output is correct |
57 |
Correct |
394 ms |
27156 KB |
Output is correct |
58 |
Correct |
377 ms |
27116 KB |
Output is correct |
59 |
Correct |
385 ms |
27244 KB |
Output is correct |
60 |
Correct |
378 ms |
27116 KB |
Output is correct |
61 |
Correct |
377 ms |
27204 KB |
Output is correct |
62 |
Correct |
387 ms |
27216 KB |
Output is correct |
63 |
Correct |
387 ms |
27116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
393 ms |
26348 KB |
Output is correct |
2 |
Correct |
376 ms |
26348 KB |
Output is correct |
3 |
Correct |
364 ms |
26220 KB |
Output is correct |
4 |
Correct |
374 ms |
26220 KB |
Output is correct |
5 |
Correct |
379 ms |
26220 KB |
Output is correct |
6 |
Correct |
387 ms |
26344 KB |
Output is correct |
7 |
Correct |
369 ms |
26348 KB |
Output is correct |
8 |
Correct |
375 ms |
26348 KB |
Output is correct |
9 |
Correct |
374 ms |
26220 KB |
Output is correct |
10 |
Correct |
420 ms |
26292 KB |
Output is correct |
11 |
Correct |
369 ms |
26220 KB |
Output is correct |
12 |
Correct |
397 ms |
26348 KB |
Output is correct |
13 |
Correct |
400 ms |
26348 KB |
Output is correct |
14 |
Correct |
393 ms |
26276 KB |
Output is correct |
15 |
Correct |
373 ms |
26348 KB |
Output is correct |
16 |
Correct |
458 ms |
26220 KB |
Output is correct |
17 |
Correct |
382 ms |
26348 KB |
Output is correct |
18 |
Correct |
413 ms |
26220 KB |
Output is correct |
19 |
Correct |
381 ms |
26220 KB |
Output is correct |
20 |
Correct |
369 ms |
26220 KB |
Output is correct |
21 |
Correct |
374 ms |
26348 KB |
Output is correct |
22 |
Correct |
376 ms |
26860 KB |
Output is correct |
23 |
Correct |
378 ms |
26988 KB |
Output is correct |
24 |
Correct |
372 ms |
26988 KB |
Output is correct |
25 |
Correct |
390 ms |
26860 KB |
Output is correct |
26 |
Correct |
376 ms |
26988 KB |
Output is correct |
27 |
Correct |
376 ms |
26888 KB |
Output is correct |
28 |
Correct |
381 ms |
27116 KB |
Output is correct |
29 |
Correct |
385 ms |
26860 KB |
Output is correct |
30 |
Correct |
377 ms |
26988 KB |
Output is correct |
31 |
Correct |
372 ms |
26860 KB |
Output is correct |
32 |
Correct |
412 ms |
26856 KB |
Output is correct |
33 |
Correct |
377 ms |
26860 KB |
Output is correct |
34 |
Correct |
387 ms |
27136 KB |
Output is correct |
35 |
Correct |
378 ms |
26988 KB |
Output is correct |
36 |
Correct |
381 ms |
27040 KB |
Output is correct |
37 |
Correct |
387 ms |
26920 KB |
Output is correct |
38 |
Correct |
375 ms |
27116 KB |
Output is correct |
39 |
Correct |
376 ms |
26860 KB |
Output is correct |
40 |
Correct |
387 ms |
26860 KB |
Output is correct |
41 |
Correct |
374 ms |
26988 KB |
Output is correct |
42 |
Correct |
368 ms |
26860 KB |
Output is correct |
43 |
Correct |
399 ms |
27064 KB |
Output is correct |
44 |
Correct |
393 ms |
27244 KB |
Output is correct |
45 |
Correct |
374 ms |
27116 KB |
Output is correct |
46 |
Correct |
383 ms |
27244 KB |
Output is correct |
47 |
Correct |
380 ms |
27116 KB |
Output is correct |
48 |
Correct |
376 ms |
27116 KB |
Output is correct |
49 |
Correct |
384 ms |
27116 KB |
Output is correct |
50 |
Correct |
385 ms |
27244 KB |
Output is correct |
51 |
Correct |
382 ms |
27116 KB |
Output is correct |
52 |
Correct |
398 ms |
27116 KB |
Output is correct |
53 |
Correct |
379 ms |
27116 KB |
Output is correct |
54 |
Correct |
397 ms |
27244 KB |
Output is correct |
55 |
Correct |
384 ms |
27116 KB |
Output is correct |
56 |
Correct |
383 ms |
27116 KB |
Output is correct |
57 |
Correct |
394 ms |
27156 KB |
Output is correct |
58 |
Correct |
377 ms |
27116 KB |
Output is correct |
59 |
Correct |
385 ms |
27244 KB |
Output is correct |
60 |
Correct |
378 ms |
27116 KB |
Output is correct |
61 |
Correct |
377 ms |
27204 KB |
Output is correct |
62 |
Correct |
387 ms |
27216 KB |
Output is correct |
63 |
Correct |
387 ms |
27116 KB |
Output is correct |
64 |
Runtime error |
4 ms |
1132 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
65 |
Halted |
0 ms |
0 KB |
- |