#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using lint = long long;
using intp = pair<int,int>;
using vint = vector<int>;
const int MAX_N=100010;
const int AN=62;
const int MAX_L=8;
const lint MOD=998244353;
int n;
vector<string> w;
lint cnt[MAX_L][AN][AN];
lint cnt2[MAX_L][AN][AN][AN];
int lti(char c)
{
if('A'<=c<='Z')
return c-'A';
if('a'<=c<='z')
return c-'a'+26;
return c-'0'+52;
}
string revs(string s)
{
int l=s.size();
for(int i=0;i*2<l;i++)
swap(s[i],s[l-1-i]);
return s;
}
void value(lint &v,const int &l,const int &a1,const int &a2,const int &a3,const int &a4)
{
int times=24;
if(a1==a2 && a2==a3 && a3==a4)
times=1;
else if(a2==a3 && (a1==a2 || a3==a4))
times=4;
else if(a1==a2 && a3==a4)
times=6;
else if(a1==a2 || a2==a3 || a3==a4)
times=12;
v=(v+(((cnt2[l][a1][a2][a3]*cnt2[l][a1][a2][a4])%MOD)*((cnt2[l][a1][a3][a4]*cnt2[l][a2][a3][a4])%MOD)%MOD)*times)%MOD;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n;
for(int i=0;i<n;i++)
{
string s;
cin >> s;
w.push_back(s);
w.push_back(revs(s));
}
sort(w.begin(),w.end());
w.resize(unique(w.begin(),w.end())-w.begin());
for(auto s : w)
cnt[s.size()-3][lti(s[0])][lti(s[s.size()-1])]++;
for(int l=0;l<8;l++)
for(int a1=0;a1<AN;a1++)
for(int a2=a1;a2<AN;a2++)
for(int a3=a2;a3<AN;a3++)
{
lint v=0;
for(int t=0;t<AN;t++)
v=(v+cnt[l][a1][t]*cnt[l][a2][t]*cnt[l][a3][t])%MOD;
cnt2[l][a1][a2][a3]=v;
}
lint ans=0;
for(int l=0;l<8;l++)
for(int a1=0;a1<AN;a1++)
for(int a2=a1;a2<AN;a2++)
for(int a3=a2;a3<AN;a3++)
for(int a4=a3;a4<AN;a4++)
value(ans,l,a1,a2,a3,a4);
cout << ans;
return 0;
}
Compilation message
cubeword.cpp: In function 'int lti(char)':
cubeword.cpp:22:14: warning: comparison of constant ''Z'' with boolean expression is always true [-Wbool-compare]
22 | if('A'<=c<='Z')
| ~~~~~~^~~~~
cubeword.cpp:22:11: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
22 | if('A'<=c<='Z')
| ~~~^~~
cubeword.cpp:24:14: warning: comparison of constant ''z'' with boolean expression is always true [-Wbool-compare]
24 | if('a'<=c<='z')
| ~~~~~~^~~~~
cubeword.cpp:24:11: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
24 | if('a'<=c<='z')
| ~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
183 ms |
23220 KB |
Output is correct |
2 |
Correct |
189 ms |
23476 KB |
Output is correct |
3 |
Correct |
184 ms |
24248 KB |
Output is correct |
4 |
Correct |
192 ms |
23608 KB |
Output is correct |
5 |
Correct |
182 ms |
23220 KB |
Output is correct |
6 |
Correct |
181 ms |
23340 KB |
Output is correct |
7 |
Correct |
186 ms |
22284 KB |
Output is correct |
8 |
Correct |
183 ms |
22456 KB |
Output is correct |
9 |
Correct |
189 ms |
23476 KB |
Output is correct |
10 |
Correct |
182 ms |
23992 KB |
Output is correct |
11 |
Correct |
189 ms |
22844 KB |
Output is correct |
12 |
Correct |
182 ms |
23476 KB |
Output is correct |
13 |
Correct |
183 ms |
23576 KB |
Output is correct |
14 |
Correct |
184 ms |
23732 KB |
Output is correct |
15 |
Correct |
184 ms |
23732 KB |
Output is correct |
16 |
Correct |
182 ms |
22900 KB |
Output is correct |
17 |
Correct |
193 ms |
23736 KB |
Output is correct |
18 |
Correct |
184 ms |
22216 KB |
Output is correct |
19 |
Correct |
188 ms |
23476 KB |
Output is correct |
20 |
Correct |
184 ms |
24248 KB |
Output is correct |
21 |
Correct |
184 ms |
22712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
183 ms |
23220 KB |
Output is correct |
2 |
Correct |
189 ms |
23476 KB |
Output is correct |
3 |
Correct |
184 ms |
24248 KB |
Output is correct |
4 |
Correct |
192 ms |
23608 KB |
Output is correct |
5 |
Correct |
182 ms |
23220 KB |
Output is correct |
6 |
Correct |
181 ms |
23340 KB |
Output is correct |
7 |
Correct |
186 ms |
22284 KB |
Output is correct |
8 |
Correct |
183 ms |
22456 KB |
Output is correct |
9 |
Correct |
189 ms |
23476 KB |
Output is correct |
10 |
Correct |
182 ms |
23992 KB |
Output is correct |
11 |
Correct |
189 ms |
22844 KB |
Output is correct |
12 |
Correct |
182 ms |
23476 KB |
Output is correct |
13 |
Correct |
183 ms |
23576 KB |
Output is correct |
14 |
Correct |
184 ms |
23732 KB |
Output is correct |
15 |
Correct |
184 ms |
23732 KB |
Output is correct |
16 |
Correct |
182 ms |
22900 KB |
Output is correct |
17 |
Correct |
193 ms |
23736 KB |
Output is correct |
18 |
Correct |
184 ms |
22216 KB |
Output is correct |
19 |
Correct |
188 ms |
23476 KB |
Output is correct |
20 |
Correct |
184 ms |
24248 KB |
Output is correct |
21 |
Correct |
184 ms |
22712 KB |
Output is correct |
22 |
Correct |
179 ms |
22232 KB |
Output is correct |
23 |
Correct |
187 ms |
22196 KB |
Output is correct |
24 |
Correct |
184 ms |
22964 KB |
Output is correct |
25 |
Correct |
181 ms |
24248 KB |
Output is correct |
26 |
Correct |
183 ms |
22300 KB |
Output is correct |
27 |
Correct |
187 ms |
23224 KB |
Output is correct |
28 |
Correct |
179 ms |
22268 KB |
Output is correct |
29 |
Correct |
182 ms |
22700 KB |
Output is correct |
30 |
Correct |
181 ms |
22200 KB |
Output is correct |
31 |
Correct |
178 ms |
22456 KB |
Output is correct |
32 |
Correct |
186 ms |
23448 KB |
Output is correct |
33 |
Correct |
180 ms |
22340 KB |
Output is correct |
34 |
Correct |
179 ms |
23224 KB |
Output is correct |
35 |
Correct |
189 ms |
22712 KB |
Output is correct |
36 |
Correct |
179 ms |
22924 KB |
Output is correct |
37 |
Correct |
177 ms |
22196 KB |
Output is correct |
38 |
Correct |
179 ms |
23472 KB |
Output is correct |
39 |
Correct |
181 ms |
22968 KB |
Output is correct |
40 |
Correct |
171 ms |
23884 KB |
Output is correct |
41 |
Correct |
180 ms |
22708 KB |
Output is correct |
42 |
Correct |
183 ms |
22904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
183 ms |
23220 KB |
Output is correct |
2 |
Correct |
189 ms |
23476 KB |
Output is correct |
3 |
Correct |
184 ms |
24248 KB |
Output is correct |
4 |
Correct |
192 ms |
23608 KB |
Output is correct |
5 |
Correct |
182 ms |
23220 KB |
Output is correct |
6 |
Correct |
181 ms |
23340 KB |
Output is correct |
7 |
Correct |
186 ms |
22284 KB |
Output is correct |
8 |
Correct |
183 ms |
22456 KB |
Output is correct |
9 |
Correct |
189 ms |
23476 KB |
Output is correct |
10 |
Correct |
182 ms |
23992 KB |
Output is correct |
11 |
Correct |
189 ms |
22844 KB |
Output is correct |
12 |
Correct |
182 ms |
23476 KB |
Output is correct |
13 |
Correct |
183 ms |
23576 KB |
Output is correct |
14 |
Correct |
184 ms |
23732 KB |
Output is correct |
15 |
Correct |
184 ms |
23732 KB |
Output is correct |
16 |
Correct |
182 ms |
22900 KB |
Output is correct |
17 |
Correct |
193 ms |
23736 KB |
Output is correct |
18 |
Correct |
184 ms |
22216 KB |
Output is correct |
19 |
Correct |
188 ms |
23476 KB |
Output is correct |
20 |
Correct |
184 ms |
24248 KB |
Output is correct |
21 |
Correct |
184 ms |
22712 KB |
Output is correct |
22 |
Correct |
179 ms |
22232 KB |
Output is correct |
23 |
Correct |
187 ms |
22196 KB |
Output is correct |
24 |
Correct |
184 ms |
22964 KB |
Output is correct |
25 |
Correct |
181 ms |
24248 KB |
Output is correct |
26 |
Correct |
183 ms |
22300 KB |
Output is correct |
27 |
Correct |
187 ms |
23224 KB |
Output is correct |
28 |
Correct |
179 ms |
22268 KB |
Output is correct |
29 |
Correct |
182 ms |
22700 KB |
Output is correct |
30 |
Correct |
181 ms |
22200 KB |
Output is correct |
31 |
Correct |
178 ms |
22456 KB |
Output is correct |
32 |
Correct |
186 ms |
23448 KB |
Output is correct |
33 |
Correct |
180 ms |
22340 KB |
Output is correct |
34 |
Correct |
179 ms |
23224 KB |
Output is correct |
35 |
Correct |
189 ms |
22712 KB |
Output is correct |
36 |
Correct |
179 ms |
22924 KB |
Output is correct |
37 |
Correct |
177 ms |
22196 KB |
Output is correct |
38 |
Correct |
179 ms |
23472 KB |
Output is correct |
39 |
Correct |
181 ms |
22968 KB |
Output is correct |
40 |
Correct |
171 ms |
23884 KB |
Output is correct |
41 |
Correct |
180 ms |
22708 KB |
Output is correct |
42 |
Correct |
183 ms |
22904 KB |
Output is correct |
43 |
Correct |
186 ms |
22964 KB |
Output is correct |
44 |
Correct |
180 ms |
22964 KB |
Output is correct |
45 |
Correct |
181 ms |
22740 KB |
Output is correct |
46 |
Correct |
177 ms |
23088 KB |
Output is correct |
47 |
Correct |
181 ms |
22672 KB |
Output is correct |
48 |
Correct |
199 ms |
23220 KB |
Output is correct |
49 |
Correct |
182 ms |
23224 KB |
Output is correct |
50 |
Correct |
178 ms |
22708 KB |
Output is correct |
51 |
Correct |
188 ms |
22968 KB |
Output is correct |
52 |
Correct |
181 ms |
22968 KB |
Output is correct |
53 |
Correct |
184 ms |
24248 KB |
Output is correct |
54 |
Correct |
179 ms |
23412 KB |
Output is correct |
55 |
Correct |
183 ms |
23992 KB |
Output is correct |
56 |
Correct |
179 ms |
22712 KB |
Output is correct |
57 |
Correct |
183 ms |
23476 KB |
Output is correct |
58 |
Correct |
182 ms |
23044 KB |
Output is correct |
59 |
Correct |
208 ms |
23016 KB |
Output is correct |
60 |
Correct |
183 ms |
23480 KB |
Output is correct |
61 |
Correct |
186 ms |
23760 KB |
Output is correct |
62 |
Correct |
180 ms |
23220 KB |
Output is correct |
63 |
Correct |
192 ms |
23076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
183 ms |
23220 KB |
Output is correct |
2 |
Correct |
189 ms |
23476 KB |
Output is correct |
3 |
Correct |
184 ms |
24248 KB |
Output is correct |
4 |
Correct |
192 ms |
23608 KB |
Output is correct |
5 |
Correct |
182 ms |
23220 KB |
Output is correct |
6 |
Correct |
181 ms |
23340 KB |
Output is correct |
7 |
Correct |
186 ms |
22284 KB |
Output is correct |
8 |
Correct |
183 ms |
22456 KB |
Output is correct |
9 |
Correct |
189 ms |
23476 KB |
Output is correct |
10 |
Correct |
182 ms |
23992 KB |
Output is correct |
11 |
Correct |
189 ms |
22844 KB |
Output is correct |
12 |
Correct |
182 ms |
23476 KB |
Output is correct |
13 |
Correct |
183 ms |
23576 KB |
Output is correct |
14 |
Correct |
184 ms |
23732 KB |
Output is correct |
15 |
Correct |
184 ms |
23732 KB |
Output is correct |
16 |
Correct |
182 ms |
22900 KB |
Output is correct |
17 |
Correct |
193 ms |
23736 KB |
Output is correct |
18 |
Correct |
184 ms |
22216 KB |
Output is correct |
19 |
Correct |
188 ms |
23476 KB |
Output is correct |
20 |
Correct |
184 ms |
24248 KB |
Output is correct |
21 |
Correct |
184 ms |
22712 KB |
Output is correct |
22 |
Correct |
179 ms |
22232 KB |
Output is correct |
23 |
Correct |
187 ms |
22196 KB |
Output is correct |
24 |
Correct |
184 ms |
22964 KB |
Output is correct |
25 |
Correct |
181 ms |
24248 KB |
Output is correct |
26 |
Correct |
183 ms |
22300 KB |
Output is correct |
27 |
Correct |
187 ms |
23224 KB |
Output is correct |
28 |
Correct |
179 ms |
22268 KB |
Output is correct |
29 |
Correct |
182 ms |
22700 KB |
Output is correct |
30 |
Correct |
181 ms |
22200 KB |
Output is correct |
31 |
Correct |
178 ms |
22456 KB |
Output is correct |
32 |
Correct |
186 ms |
23448 KB |
Output is correct |
33 |
Correct |
180 ms |
22340 KB |
Output is correct |
34 |
Correct |
179 ms |
23224 KB |
Output is correct |
35 |
Correct |
189 ms |
22712 KB |
Output is correct |
36 |
Correct |
179 ms |
22924 KB |
Output is correct |
37 |
Correct |
177 ms |
22196 KB |
Output is correct |
38 |
Correct |
179 ms |
23472 KB |
Output is correct |
39 |
Correct |
181 ms |
22968 KB |
Output is correct |
40 |
Correct |
171 ms |
23884 KB |
Output is correct |
41 |
Correct |
180 ms |
22708 KB |
Output is correct |
42 |
Correct |
183 ms |
22904 KB |
Output is correct |
43 |
Correct |
186 ms |
22964 KB |
Output is correct |
44 |
Correct |
180 ms |
22964 KB |
Output is correct |
45 |
Correct |
181 ms |
22740 KB |
Output is correct |
46 |
Correct |
177 ms |
23088 KB |
Output is correct |
47 |
Correct |
181 ms |
22672 KB |
Output is correct |
48 |
Correct |
199 ms |
23220 KB |
Output is correct |
49 |
Correct |
182 ms |
23224 KB |
Output is correct |
50 |
Correct |
178 ms |
22708 KB |
Output is correct |
51 |
Correct |
188 ms |
22968 KB |
Output is correct |
52 |
Correct |
181 ms |
22968 KB |
Output is correct |
53 |
Correct |
184 ms |
24248 KB |
Output is correct |
54 |
Correct |
179 ms |
23412 KB |
Output is correct |
55 |
Correct |
183 ms |
23992 KB |
Output is correct |
56 |
Correct |
179 ms |
22712 KB |
Output is correct |
57 |
Correct |
183 ms |
23476 KB |
Output is correct |
58 |
Correct |
182 ms |
23044 KB |
Output is correct |
59 |
Correct |
208 ms |
23016 KB |
Output is correct |
60 |
Correct |
183 ms |
23480 KB |
Output is correct |
61 |
Correct |
186 ms |
23760 KB |
Output is correct |
62 |
Correct |
180 ms |
23220 KB |
Output is correct |
63 |
Correct |
192 ms |
23076 KB |
Output is correct |
64 |
Incorrect |
182 ms |
23220 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |