#include<bits/stdc++.h>
using namespace std;
vector<string> v[11];
const int MOD = 998244353;
void add(int &x, long long y){
y%=MOD;
x+=y;
if(x>=MOD)
x-=MOD;
if(x<0)
x+=MOD;
}
int codes(char c){
if(c >= 'a' && c <= 'z')
return c - 'a';
else if( c >= 'A' && c<= 'Z')
return c - 'A' + 'z' - 'a' + 1;
else if(c >= '0' && c <= '9'){
return c - '0' + 'Z' - 'A' + 1 + 'z' - 'a' + 1;
}
assert(0);
return -1;
}
const int SIGMA = 'Z' - 'A' + 1 + 'z' - 'a' + 1 + '9' - '0' + 1 + 1;
int nw[SIGMA][SIGMA];
int nr[SIGMA][SIGMA][SIGMA];
int coef(int l1, int l2, int l3, int l4){
if(l1 == l4)
return 1;
if(l1 == l3 || l2 == l4)
return 4;
if(l1 == l2 && l3 == l4)
return 6;
if(l1 == l2 || l2 == l3 || l3 == l4)
return 12;
return 24;
}
int main()
{
//freopen(".in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n;
cin>>n;
for(int i = 1; i <=n; i++){
string s;
cin>>s;
int len = s.size();
v[len].push_back(s);
reverse(s.begin(), s.end());
v[len].push_back(s);
}
int ans = 0;
for(int len = 3; len<=10; len++){
// doar ce e unic
sort(v[len].begin(), v[len].end());
auto last = unique(v[len].begin(), v[len].end());
v[len].erase(last, v[len].end());
for(string x:v[len]){
nw[codes(x[0])][codes(x[x.size() - 1])]++;
}
for(int l1 = 0; l1 < SIGMA; l1++){
for(int l2 = l1; l2 < SIGMA; l2++){
for(int l3 = l2; l3 < SIGMA; l3++){
for(int l4 = 0; l4 < SIGMA; l4++){
long long ad = 1LL * nw[l4][l1] * nw[l4][l2] % MOD * nw[l4][l3] % MOD;
if(add)
add(nr[l1][l2][l3], ad);
}
}
}
}
for(int l1 = 0; l1 < SIGMA; l1++){
for(int l2 = l1; l2 < SIGMA; l2++){
for(int l3 = l2; l3 < SIGMA; l3++){
for(int l4 = l3; l4 < SIGMA; l4++){
long long nwc = 1LL *nr[l1][l2][l3] * nr[l1][l2][l4] % MOD * nr[l1][l3][l4] % MOD * nr[l2][l3][l4] % MOD;
if(nwc)
add(ans, 1LL *nwc * coef(l1, l2, l3, l4));
}
}
}
}
memset(nr, 0, sizeof(nr));
memset(nw, 0, sizeof(nw));
}
cout<<ans;
return 0;
}
Compilation message
cubeword.cpp: In function 'int main()':
cubeword.cpp:67:16: warning: the address of 'void add(int&, long long int)' will never be NULL [-Waddress]
67 | if(add)
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
223 ms |
8168 KB |
Output is correct |
2 |
Correct |
226 ms |
8212 KB |
Output is correct |
3 |
Correct |
216 ms |
8128 KB |
Output is correct |
4 |
Correct |
220 ms |
8232 KB |
Output is correct |
5 |
Correct |
226 ms |
8300 KB |
Output is correct |
6 |
Correct |
227 ms |
8380 KB |
Output is correct |
7 |
Correct |
220 ms |
8296 KB |
Output is correct |
8 |
Correct |
223 ms |
7836 KB |
Output is correct |
9 |
Correct |
219 ms |
7880 KB |
Output is correct |
10 |
Correct |
220 ms |
8080 KB |
Output is correct |
11 |
Correct |
220 ms |
8096 KB |
Output is correct |
12 |
Correct |
217 ms |
7972 KB |
Output is correct |
13 |
Correct |
216 ms |
7980 KB |
Output is correct |
14 |
Correct |
223 ms |
7936 KB |
Output is correct |
15 |
Correct |
218 ms |
7916 KB |
Output is correct |
16 |
Correct |
222 ms |
7916 KB |
Output is correct |
17 |
Correct |
220 ms |
8020 KB |
Output is correct |
18 |
Correct |
226 ms |
7932 KB |
Output is correct |
19 |
Correct |
218 ms |
7892 KB |
Output is correct |
20 |
Correct |
223 ms |
7944 KB |
Output is correct |
21 |
Correct |
237 ms |
7968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
223 ms |
8168 KB |
Output is correct |
2 |
Correct |
226 ms |
8212 KB |
Output is correct |
3 |
Correct |
216 ms |
8128 KB |
Output is correct |
4 |
Correct |
220 ms |
8232 KB |
Output is correct |
5 |
Correct |
226 ms |
8300 KB |
Output is correct |
6 |
Correct |
227 ms |
8380 KB |
Output is correct |
7 |
Correct |
220 ms |
8296 KB |
Output is correct |
8 |
Correct |
223 ms |
7836 KB |
Output is correct |
9 |
Correct |
219 ms |
7880 KB |
Output is correct |
10 |
Correct |
220 ms |
8080 KB |
Output is correct |
11 |
Correct |
220 ms |
8096 KB |
Output is correct |
12 |
Correct |
217 ms |
7972 KB |
Output is correct |
13 |
Correct |
216 ms |
7980 KB |
Output is correct |
14 |
Correct |
223 ms |
7936 KB |
Output is correct |
15 |
Correct |
218 ms |
7916 KB |
Output is correct |
16 |
Correct |
222 ms |
7916 KB |
Output is correct |
17 |
Correct |
220 ms |
8020 KB |
Output is correct |
18 |
Correct |
226 ms |
7932 KB |
Output is correct |
19 |
Correct |
218 ms |
7892 KB |
Output is correct |
20 |
Correct |
223 ms |
7944 KB |
Output is correct |
21 |
Correct |
237 ms |
7968 KB |
Output is correct |
22 |
Correct |
219 ms |
7676 KB |
Output is correct |
23 |
Correct |
220 ms |
7628 KB |
Output is correct |
24 |
Correct |
212 ms |
7884 KB |
Output is correct |
25 |
Correct |
222 ms |
7876 KB |
Output is correct |
26 |
Correct |
224 ms |
7684 KB |
Output is correct |
27 |
Correct |
217 ms |
7952 KB |
Output is correct |
28 |
Correct |
220 ms |
7752 KB |
Output is correct |
29 |
Correct |
215 ms |
7796 KB |
Output is correct |
30 |
Correct |
251 ms |
7704 KB |
Output is correct |
31 |
Correct |
219 ms |
7760 KB |
Output is correct |
32 |
Correct |
216 ms |
7620 KB |
Output is correct |
33 |
Correct |
220 ms |
7600 KB |
Output is correct |
34 |
Correct |
217 ms |
7904 KB |
Output is correct |
35 |
Correct |
219 ms |
8000 KB |
Output is correct |
36 |
Correct |
218 ms |
7816 KB |
Output is correct |
37 |
Correct |
215 ms |
7764 KB |
Output is correct |
38 |
Correct |
219 ms |
7864 KB |
Output is correct |
39 |
Correct |
218 ms |
7836 KB |
Output is correct |
40 |
Correct |
220 ms |
7896 KB |
Output is correct |
41 |
Correct |
222 ms |
7892 KB |
Output is correct |
42 |
Correct |
217 ms |
7716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
223 ms |
8168 KB |
Output is correct |
2 |
Correct |
226 ms |
8212 KB |
Output is correct |
3 |
Correct |
216 ms |
8128 KB |
Output is correct |
4 |
Correct |
220 ms |
8232 KB |
Output is correct |
5 |
Correct |
226 ms |
8300 KB |
Output is correct |
6 |
Correct |
227 ms |
8380 KB |
Output is correct |
7 |
Correct |
220 ms |
8296 KB |
Output is correct |
8 |
Correct |
223 ms |
7836 KB |
Output is correct |
9 |
Correct |
219 ms |
7880 KB |
Output is correct |
10 |
Correct |
220 ms |
8080 KB |
Output is correct |
11 |
Correct |
220 ms |
8096 KB |
Output is correct |
12 |
Correct |
217 ms |
7972 KB |
Output is correct |
13 |
Correct |
216 ms |
7980 KB |
Output is correct |
14 |
Correct |
223 ms |
7936 KB |
Output is correct |
15 |
Correct |
218 ms |
7916 KB |
Output is correct |
16 |
Correct |
222 ms |
7916 KB |
Output is correct |
17 |
Correct |
220 ms |
8020 KB |
Output is correct |
18 |
Correct |
226 ms |
7932 KB |
Output is correct |
19 |
Correct |
218 ms |
7892 KB |
Output is correct |
20 |
Correct |
223 ms |
7944 KB |
Output is correct |
21 |
Correct |
237 ms |
7968 KB |
Output is correct |
22 |
Correct |
219 ms |
7676 KB |
Output is correct |
23 |
Correct |
220 ms |
7628 KB |
Output is correct |
24 |
Correct |
212 ms |
7884 KB |
Output is correct |
25 |
Correct |
222 ms |
7876 KB |
Output is correct |
26 |
Correct |
224 ms |
7684 KB |
Output is correct |
27 |
Correct |
217 ms |
7952 KB |
Output is correct |
28 |
Correct |
220 ms |
7752 KB |
Output is correct |
29 |
Correct |
215 ms |
7796 KB |
Output is correct |
30 |
Correct |
251 ms |
7704 KB |
Output is correct |
31 |
Correct |
219 ms |
7760 KB |
Output is correct |
32 |
Correct |
216 ms |
7620 KB |
Output is correct |
33 |
Correct |
220 ms |
7600 KB |
Output is correct |
34 |
Correct |
217 ms |
7904 KB |
Output is correct |
35 |
Correct |
219 ms |
8000 KB |
Output is correct |
36 |
Correct |
218 ms |
7816 KB |
Output is correct |
37 |
Correct |
215 ms |
7764 KB |
Output is correct |
38 |
Correct |
219 ms |
7864 KB |
Output is correct |
39 |
Correct |
218 ms |
7836 KB |
Output is correct |
40 |
Correct |
220 ms |
7896 KB |
Output is correct |
41 |
Correct |
222 ms |
7892 KB |
Output is correct |
42 |
Correct |
217 ms |
7716 KB |
Output is correct |
43 |
Correct |
221 ms |
7648 KB |
Output is correct |
44 |
Correct |
236 ms |
7792 KB |
Output is correct |
45 |
Correct |
225 ms |
7712 KB |
Output is correct |
46 |
Correct |
223 ms |
7672 KB |
Output is correct |
47 |
Correct |
229 ms |
7736 KB |
Output is correct |
48 |
Correct |
223 ms |
8028 KB |
Output is correct |
49 |
Correct |
223 ms |
8096 KB |
Output is correct |
50 |
Correct |
222 ms |
8116 KB |
Output is correct |
51 |
Correct |
224 ms |
7984 KB |
Output is correct |
52 |
Correct |
224 ms |
7856 KB |
Output is correct |
53 |
Correct |
222 ms |
7664 KB |
Output is correct |
54 |
Correct |
224 ms |
7992 KB |
Output is correct |
55 |
Correct |
222 ms |
8064 KB |
Output is correct |
56 |
Correct |
224 ms |
7684 KB |
Output is correct |
57 |
Correct |
222 ms |
7932 KB |
Output is correct |
58 |
Correct |
221 ms |
8104 KB |
Output is correct |
59 |
Correct |
218 ms |
7988 KB |
Output is correct |
60 |
Correct |
224 ms |
8024 KB |
Output is correct |
61 |
Correct |
225 ms |
7740 KB |
Output is correct |
62 |
Correct |
219 ms |
7988 KB |
Output is correct |
63 |
Correct |
222 ms |
7968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
223 ms |
8168 KB |
Output is correct |
2 |
Correct |
226 ms |
8212 KB |
Output is correct |
3 |
Correct |
216 ms |
8128 KB |
Output is correct |
4 |
Correct |
220 ms |
8232 KB |
Output is correct |
5 |
Correct |
226 ms |
8300 KB |
Output is correct |
6 |
Correct |
227 ms |
8380 KB |
Output is correct |
7 |
Correct |
220 ms |
8296 KB |
Output is correct |
8 |
Correct |
223 ms |
7836 KB |
Output is correct |
9 |
Correct |
219 ms |
7880 KB |
Output is correct |
10 |
Correct |
220 ms |
8080 KB |
Output is correct |
11 |
Correct |
220 ms |
8096 KB |
Output is correct |
12 |
Correct |
217 ms |
7972 KB |
Output is correct |
13 |
Correct |
216 ms |
7980 KB |
Output is correct |
14 |
Correct |
223 ms |
7936 KB |
Output is correct |
15 |
Correct |
218 ms |
7916 KB |
Output is correct |
16 |
Correct |
222 ms |
7916 KB |
Output is correct |
17 |
Correct |
220 ms |
8020 KB |
Output is correct |
18 |
Correct |
226 ms |
7932 KB |
Output is correct |
19 |
Correct |
218 ms |
7892 KB |
Output is correct |
20 |
Correct |
223 ms |
7944 KB |
Output is correct |
21 |
Correct |
237 ms |
7968 KB |
Output is correct |
22 |
Correct |
219 ms |
7676 KB |
Output is correct |
23 |
Correct |
220 ms |
7628 KB |
Output is correct |
24 |
Correct |
212 ms |
7884 KB |
Output is correct |
25 |
Correct |
222 ms |
7876 KB |
Output is correct |
26 |
Correct |
224 ms |
7684 KB |
Output is correct |
27 |
Correct |
217 ms |
7952 KB |
Output is correct |
28 |
Correct |
220 ms |
7752 KB |
Output is correct |
29 |
Correct |
215 ms |
7796 KB |
Output is correct |
30 |
Correct |
251 ms |
7704 KB |
Output is correct |
31 |
Correct |
219 ms |
7760 KB |
Output is correct |
32 |
Correct |
216 ms |
7620 KB |
Output is correct |
33 |
Correct |
220 ms |
7600 KB |
Output is correct |
34 |
Correct |
217 ms |
7904 KB |
Output is correct |
35 |
Correct |
219 ms |
8000 KB |
Output is correct |
36 |
Correct |
218 ms |
7816 KB |
Output is correct |
37 |
Correct |
215 ms |
7764 KB |
Output is correct |
38 |
Correct |
219 ms |
7864 KB |
Output is correct |
39 |
Correct |
218 ms |
7836 KB |
Output is correct |
40 |
Correct |
220 ms |
7896 KB |
Output is correct |
41 |
Correct |
222 ms |
7892 KB |
Output is correct |
42 |
Correct |
217 ms |
7716 KB |
Output is correct |
43 |
Correct |
221 ms |
7648 KB |
Output is correct |
44 |
Correct |
236 ms |
7792 KB |
Output is correct |
45 |
Correct |
225 ms |
7712 KB |
Output is correct |
46 |
Correct |
223 ms |
7672 KB |
Output is correct |
47 |
Correct |
229 ms |
7736 KB |
Output is correct |
48 |
Correct |
223 ms |
8028 KB |
Output is correct |
49 |
Correct |
223 ms |
8096 KB |
Output is correct |
50 |
Correct |
222 ms |
8116 KB |
Output is correct |
51 |
Correct |
224 ms |
7984 KB |
Output is correct |
52 |
Correct |
224 ms |
7856 KB |
Output is correct |
53 |
Correct |
222 ms |
7664 KB |
Output is correct |
54 |
Correct |
224 ms |
7992 KB |
Output is correct |
55 |
Correct |
222 ms |
8064 KB |
Output is correct |
56 |
Correct |
224 ms |
7684 KB |
Output is correct |
57 |
Correct |
222 ms |
7932 KB |
Output is correct |
58 |
Correct |
221 ms |
8104 KB |
Output is correct |
59 |
Correct |
218 ms |
7988 KB |
Output is correct |
60 |
Correct |
224 ms |
8024 KB |
Output is correct |
61 |
Correct |
225 ms |
7740 KB |
Output is correct |
62 |
Correct |
219 ms |
7988 KB |
Output is correct |
63 |
Correct |
222 ms |
7968 KB |
Output is correct |
64 |
Correct |
284 ms |
8016 KB |
Output is correct |
65 |
Correct |
283 ms |
8712 KB |
Output is correct |
66 |
Correct |
286 ms |
8396 KB |
Output is correct |
67 |
Correct |
281 ms |
8436 KB |
Output is correct |
68 |
Correct |
283 ms |
8456 KB |
Output is correct |
69 |
Correct |
285 ms |
8596 KB |
Output is correct |
70 |
Correct |
286 ms |
8636 KB |
Output is correct |
71 |
Correct |
287 ms |
8376 KB |
Output is correct |
72 |
Correct |
281 ms |
8672 KB |
Output is correct |
73 |
Correct |
282 ms |
8512 KB |
Output is correct |
74 |
Correct |
287 ms |
8704 KB |
Output is correct |
75 |
Correct |
282 ms |
8696 KB |
Output is correct |
76 |
Correct |
282 ms |
8548 KB |
Output is correct |
77 |
Correct |
281 ms |
8456 KB |
Output is correct |
78 |
Correct |
289 ms |
8356 KB |
Output is correct |
79 |
Correct |
286 ms |
8436 KB |
Output is correct |
80 |
Correct |
284 ms |
8724 KB |
Output is correct |
81 |
Correct |
285 ms |
8772 KB |
Output is correct |
82 |
Correct |
283 ms |
8816 KB |
Output is correct |
83 |
Correct |
284 ms |
8600 KB |
Output is correct |
84 |
Correct |
289 ms |
8812 KB |
Output is correct |