#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const long long int mo=998244353;
int n;
ll t[50][50][50];
ll g[50][50];
int turn(char x) {
if (('a'<=x)&&('p'>=x)) {
return(x-'a');
}
return(x-'A'+16);
}
void eval(string z) {
if (z[0]!=z[z.size()-1]) {
g[turn(z[0])][turn(z[z.size()-1])]=(g[turn(z[0])][turn(z[z.size()-1])]+1)%mo;
g[turn(z[z.size()-1])][turn(z[0])]=(g[turn(z[z.size()-1])][turn(z[0])]+1)%mo;
return;
}
bool isPal=1;
for (int i=0;i<z.size();i++) {
if (z[i]!=z[z.size()-1-i]) {
isPal=0;
break;
}
}
if (isPal==0) {
g[turn(z[0])][turn(z[z.size()-1])]=(g[turn(z[0])][turn(z[z.size()-1])]+2)%mo;
} else {
g[turn(z[0])][turn(z[z.size()-1])]=(g[turn(z[0])][turn(z[z.size()-1])]+1)%mo;
}
return;
}
vector<string> f;
bool kis(string a,string b) {
return((a.size()<b.size())||((a.size()==b.size())&&(a<b)));
}
ll solve(int u,int v) {
for (int i=0;i<32;i++) {
for (int j=0;j<32;j++) {
g[i][j]=0;
for (int k=0;k<32;k++) {
t[i][j][k]=0;
}
}
}
for (int i=u;i<v;i++) {
if ((i==u)||(f[i]!=f[i-1])) {
eval(f[i]);
}
}
for (int i=0;i<32;i++) {
for (int j=0;j<32;j++) {
for (int k=0;k<32;k++) {
for (int mid=0;mid<32;mid++) {
t[i][j][k]=(t[i][j][k]+(((g[i][mid]*g[j][mid])%mo)*g[k][mid])%mo)%mo;
}
}
}
}
ll ans=0;
for (int i=0;i<32;i++) {
for (int j=0;j<32;j++) {
for (int k=0;k<32;k++) {
for (int l=0;l<32;l++) {
ans=(ans+(((((t[i][j][k]*t[i][j][l])%mo)*t[i][k][l])%mo)*t[j][k][l])%mo)%mo;
}
}
}
}
return(ans);
}
string flip(string a) {
string b=a;
for (int i=0;i<a.size();i++) {
b[a.size()-i-1]=a[i];
}
if (a<b) {
return(a);
} else {
return(b);
}
}
int main()
{
cin >> n;
string a;
for (int i=0;i<n;i++) {
cin >> a;
f.push_back(flip(a));
}
sort(f.begin(),f.end(),kis);
int l=0,r=0;
ll finAns=0;
while (r<n) {
while ((r<n)&&(f[l].size()==f[r].size())) {
r++;
}
finAns=(finAns+solve(l,r))%mo;
l=r;
}
cout << finAns << endl;
return 0;
}
/*
for (int i=0;i<62;i++) {
for (int j=0;j<62;j++) {
if (g[i][j]!=0) {
cout << i << " " << j << " " << g[i][j] << endl;
}
}
}
*/
Compilation message
cubeword.cpp: In function 'void eval(std::string)':
cubeword.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int i=0;i<z.size();i++) {
| ~^~~~~~~~~
cubeword.cpp: In function 'std::string flip(std::string)':
cubeword.cpp:85:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for (int i=0;i<a.size();i++) {
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
249 ms |
4492 KB |
Output is correct |
2 |
Correct |
243 ms |
5172 KB |
Output is correct |
3 |
Correct |
249 ms |
5340 KB |
Output is correct |
4 |
Correct |
242 ms |
5228 KB |
Output is correct |
5 |
Correct |
240 ms |
5172 KB |
Output is correct |
6 |
Correct |
252 ms |
5224 KB |
Output is correct |
7 |
Correct |
239 ms |
5168 KB |
Output is correct |
8 |
Correct |
248 ms |
5228 KB |
Output is correct |
9 |
Correct |
240 ms |
5208 KB |
Output is correct |
10 |
Correct |
242 ms |
5220 KB |
Output is correct |
11 |
Correct |
241 ms |
5172 KB |
Output is correct |
12 |
Correct |
241 ms |
5172 KB |
Output is correct |
13 |
Correct |
240 ms |
5172 KB |
Output is correct |
14 |
Correct |
241 ms |
5264 KB |
Output is correct |
15 |
Correct |
239 ms |
5168 KB |
Output is correct |
16 |
Correct |
239 ms |
5176 KB |
Output is correct |
17 |
Correct |
243 ms |
5168 KB |
Output is correct |
18 |
Correct |
239 ms |
5308 KB |
Output is correct |
19 |
Correct |
241 ms |
5180 KB |
Output is correct |
20 |
Correct |
238 ms |
5160 KB |
Output is correct |
21 |
Correct |
241 ms |
5228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
249 ms |
4492 KB |
Output is correct |
2 |
Correct |
243 ms |
5172 KB |
Output is correct |
3 |
Correct |
249 ms |
5340 KB |
Output is correct |
4 |
Correct |
242 ms |
5228 KB |
Output is correct |
5 |
Correct |
240 ms |
5172 KB |
Output is correct |
6 |
Correct |
252 ms |
5224 KB |
Output is correct |
7 |
Correct |
239 ms |
5168 KB |
Output is correct |
8 |
Correct |
248 ms |
5228 KB |
Output is correct |
9 |
Correct |
240 ms |
5208 KB |
Output is correct |
10 |
Correct |
242 ms |
5220 KB |
Output is correct |
11 |
Correct |
241 ms |
5172 KB |
Output is correct |
12 |
Correct |
241 ms |
5172 KB |
Output is correct |
13 |
Correct |
240 ms |
5172 KB |
Output is correct |
14 |
Correct |
241 ms |
5264 KB |
Output is correct |
15 |
Correct |
239 ms |
5168 KB |
Output is correct |
16 |
Correct |
239 ms |
5176 KB |
Output is correct |
17 |
Correct |
243 ms |
5168 KB |
Output is correct |
18 |
Correct |
239 ms |
5308 KB |
Output is correct |
19 |
Correct |
241 ms |
5180 KB |
Output is correct |
20 |
Correct |
238 ms |
5160 KB |
Output is correct |
21 |
Correct |
241 ms |
5228 KB |
Output is correct |
22 |
Correct |
238 ms |
5200 KB |
Output is correct |
23 |
Correct |
242 ms |
5244 KB |
Output is correct |
24 |
Correct |
243 ms |
5248 KB |
Output is correct |
25 |
Correct |
242 ms |
5180 KB |
Output is correct |
26 |
Correct |
239 ms |
5284 KB |
Output is correct |
27 |
Correct |
238 ms |
5172 KB |
Output is correct |
28 |
Correct |
245 ms |
5216 KB |
Output is correct |
29 |
Correct |
241 ms |
5376 KB |
Output is correct |
30 |
Correct |
239 ms |
5172 KB |
Output is correct |
31 |
Correct |
272 ms |
5180 KB |
Output is correct |
32 |
Correct |
251 ms |
5176 KB |
Output is correct |
33 |
Correct |
235 ms |
5172 KB |
Output is correct |
34 |
Correct |
239 ms |
5276 KB |
Output is correct |
35 |
Correct |
240 ms |
5300 KB |
Output is correct |
36 |
Correct |
240 ms |
5300 KB |
Output is correct |
37 |
Correct |
252 ms |
5172 KB |
Output is correct |
38 |
Correct |
239 ms |
5220 KB |
Output is correct |
39 |
Correct |
239 ms |
5180 KB |
Output is correct |
40 |
Correct |
239 ms |
5300 KB |
Output is correct |
41 |
Correct |
243 ms |
5164 KB |
Output is correct |
42 |
Correct |
241 ms |
5252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
249 ms |
4492 KB |
Output is correct |
2 |
Correct |
243 ms |
5172 KB |
Output is correct |
3 |
Correct |
249 ms |
5340 KB |
Output is correct |
4 |
Correct |
242 ms |
5228 KB |
Output is correct |
5 |
Correct |
240 ms |
5172 KB |
Output is correct |
6 |
Correct |
252 ms |
5224 KB |
Output is correct |
7 |
Correct |
239 ms |
5168 KB |
Output is correct |
8 |
Correct |
248 ms |
5228 KB |
Output is correct |
9 |
Correct |
240 ms |
5208 KB |
Output is correct |
10 |
Correct |
242 ms |
5220 KB |
Output is correct |
11 |
Correct |
241 ms |
5172 KB |
Output is correct |
12 |
Correct |
241 ms |
5172 KB |
Output is correct |
13 |
Correct |
240 ms |
5172 KB |
Output is correct |
14 |
Correct |
241 ms |
5264 KB |
Output is correct |
15 |
Correct |
239 ms |
5168 KB |
Output is correct |
16 |
Correct |
239 ms |
5176 KB |
Output is correct |
17 |
Correct |
243 ms |
5168 KB |
Output is correct |
18 |
Correct |
239 ms |
5308 KB |
Output is correct |
19 |
Correct |
241 ms |
5180 KB |
Output is correct |
20 |
Correct |
238 ms |
5160 KB |
Output is correct |
21 |
Correct |
241 ms |
5228 KB |
Output is correct |
22 |
Correct |
238 ms |
5200 KB |
Output is correct |
23 |
Correct |
242 ms |
5244 KB |
Output is correct |
24 |
Correct |
243 ms |
5248 KB |
Output is correct |
25 |
Correct |
242 ms |
5180 KB |
Output is correct |
26 |
Correct |
239 ms |
5284 KB |
Output is correct |
27 |
Correct |
238 ms |
5172 KB |
Output is correct |
28 |
Correct |
245 ms |
5216 KB |
Output is correct |
29 |
Correct |
241 ms |
5376 KB |
Output is correct |
30 |
Correct |
239 ms |
5172 KB |
Output is correct |
31 |
Correct |
272 ms |
5180 KB |
Output is correct |
32 |
Correct |
251 ms |
5176 KB |
Output is correct |
33 |
Correct |
235 ms |
5172 KB |
Output is correct |
34 |
Correct |
239 ms |
5276 KB |
Output is correct |
35 |
Correct |
240 ms |
5300 KB |
Output is correct |
36 |
Correct |
240 ms |
5300 KB |
Output is correct |
37 |
Correct |
252 ms |
5172 KB |
Output is correct |
38 |
Correct |
239 ms |
5220 KB |
Output is correct |
39 |
Correct |
239 ms |
5180 KB |
Output is correct |
40 |
Correct |
239 ms |
5300 KB |
Output is correct |
41 |
Correct |
243 ms |
5164 KB |
Output is correct |
42 |
Correct |
241 ms |
5252 KB |
Output is correct |
43 |
Correct |
238 ms |
5108 KB |
Output is correct |
44 |
Correct |
240 ms |
5088 KB |
Output is correct |
45 |
Correct |
237 ms |
5076 KB |
Output is correct |
46 |
Correct |
238 ms |
5068 KB |
Output is correct |
47 |
Correct |
236 ms |
5052 KB |
Output is correct |
48 |
Correct |
236 ms |
5136 KB |
Output is correct |
49 |
Correct |
243 ms |
5052 KB |
Output is correct |
50 |
Correct |
244 ms |
5032 KB |
Output is correct |
51 |
Correct |
242 ms |
5052 KB |
Output is correct |
52 |
Correct |
247 ms |
5036 KB |
Output is correct |
53 |
Correct |
240 ms |
5044 KB |
Output is correct |
54 |
Correct |
240 ms |
5136 KB |
Output is correct |
55 |
Correct |
241 ms |
5044 KB |
Output is correct |
56 |
Correct |
240 ms |
5128 KB |
Output is correct |
57 |
Correct |
237 ms |
5052 KB |
Output is correct |
58 |
Correct |
244 ms |
5104 KB |
Output is correct |
59 |
Correct |
241 ms |
5132 KB |
Output is correct |
60 |
Correct |
236 ms |
5044 KB |
Output is correct |
61 |
Correct |
247 ms |
5128 KB |
Output is correct |
62 |
Correct |
237 ms |
5168 KB |
Output is correct |
63 |
Correct |
236 ms |
5044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
249 ms |
4492 KB |
Output is correct |
2 |
Correct |
243 ms |
5172 KB |
Output is correct |
3 |
Correct |
249 ms |
5340 KB |
Output is correct |
4 |
Correct |
242 ms |
5228 KB |
Output is correct |
5 |
Correct |
240 ms |
5172 KB |
Output is correct |
6 |
Correct |
252 ms |
5224 KB |
Output is correct |
7 |
Correct |
239 ms |
5168 KB |
Output is correct |
8 |
Correct |
248 ms |
5228 KB |
Output is correct |
9 |
Correct |
240 ms |
5208 KB |
Output is correct |
10 |
Correct |
242 ms |
5220 KB |
Output is correct |
11 |
Correct |
241 ms |
5172 KB |
Output is correct |
12 |
Correct |
241 ms |
5172 KB |
Output is correct |
13 |
Correct |
240 ms |
5172 KB |
Output is correct |
14 |
Correct |
241 ms |
5264 KB |
Output is correct |
15 |
Correct |
239 ms |
5168 KB |
Output is correct |
16 |
Correct |
239 ms |
5176 KB |
Output is correct |
17 |
Correct |
243 ms |
5168 KB |
Output is correct |
18 |
Correct |
239 ms |
5308 KB |
Output is correct |
19 |
Correct |
241 ms |
5180 KB |
Output is correct |
20 |
Correct |
238 ms |
5160 KB |
Output is correct |
21 |
Correct |
241 ms |
5228 KB |
Output is correct |
22 |
Correct |
238 ms |
5200 KB |
Output is correct |
23 |
Correct |
242 ms |
5244 KB |
Output is correct |
24 |
Correct |
243 ms |
5248 KB |
Output is correct |
25 |
Correct |
242 ms |
5180 KB |
Output is correct |
26 |
Correct |
239 ms |
5284 KB |
Output is correct |
27 |
Correct |
238 ms |
5172 KB |
Output is correct |
28 |
Correct |
245 ms |
5216 KB |
Output is correct |
29 |
Correct |
241 ms |
5376 KB |
Output is correct |
30 |
Correct |
239 ms |
5172 KB |
Output is correct |
31 |
Correct |
272 ms |
5180 KB |
Output is correct |
32 |
Correct |
251 ms |
5176 KB |
Output is correct |
33 |
Correct |
235 ms |
5172 KB |
Output is correct |
34 |
Correct |
239 ms |
5276 KB |
Output is correct |
35 |
Correct |
240 ms |
5300 KB |
Output is correct |
36 |
Correct |
240 ms |
5300 KB |
Output is correct |
37 |
Correct |
252 ms |
5172 KB |
Output is correct |
38 |
Correct |
239 ms |
5220 KB |
Output is correct |
39 |
Correct |
239 ms |
5180 KB |
Output is correct |
40 |
Correct |
239 ms |
5300 KB |
Output is correct |
41 |
Correct |
243 ms |
5164 KB |
Output is correct |
42 |
Correct |
241 ms |
5252 KB |
Output is correct |
43 |
Correct |
238 ms |
5108 KB |
Output is correct |
44 |
Correct |
240 ms |
5088 KB |
Output is correct |
45 |
Correct |
237 ms |
5076 KB |
Output is correct |
46 |
Correct |
238 ms |
5068 KB |
Output is correct |
47 |
Correct |
236 ms |
5052 KB |
Output is correct |
48 |
Correct |
236 ms |
5136 KB |
Output is correct |
49 |
Correct |
243 ms |
5052 KB |
Output is correct |
50 |
Correct |
244 ms |
5032 KB |
Output is correct |
51 |
Correct |
242 ms |
5052 KB |
Output is correct |
52 |
Correct |
247 ms |
5036 KB |
Output is correct |
53 |
Correct |
240 ms |
5044 KB |
Output is correct |
54 |
Correct |
240 ms |
5136 KB |
Output is correct |
55 |
Correct |
241 ms |
5044 KB |
Output is correct |
56 |
Correct |
240 ms |
5128 KB |
Output is correct |
57 |
Correct |
237 ms |
5052 KB |
Output is correct |
58 |
Correct |
244 ms |
5104 KB |
Output is correct |
59 |
Correct |
241 ms |
5132 KB |
Output is correct |
60 |
Correct |
236 ms |
5044 KB |
Output is correct |
61 |
Correct |
247 ms |
5128 KB |
Output is correct |
62 |
Correct |
237 ms |
5168 KB |
Output is correct |
63 |
Correct |
236 ms |
5044 KB |
Output is correct |
64 |
Runtime error |
245 ms |
5124 KB |
Execution killed with signal 11 |
65 |
Halted |
0 ms |
0 KB |
- |