#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int mod=998244353,alphsize=26,lgalph=62;
set<string> setik;
vector<int> muchii[25];
int nr[15][105][105];
int val[11];
int fact[5];
int n,ans,coef[15][500005];
bool found[11];
int toint(char c)
{
if(islower(c))
return c-'a'+1;
if(isupper(c))
return alphsize+c-'A'+1;
if(isdigit(c))
return 2*alphsize+c-'0'+1;
}
int gethash(int a, int b, int c)
{
return a*lgalph*lgalph+b*lgalph+c;
}
int v[5];
int repperm(int a, int b,int c, int d)
{
v[1]=a;
v[2]=b;
v[3]=c;
v[4]=d;
int rez=1*2*3*4;
int lg=0;
for(int i=1;i<=4;i++)
{
if(v[i]==v[i-1])
lg++;
else
{
rez=rez/fact[lg];
lg=1;
}
if(i==4)
rez=rez/fact[lg];
}
return rez;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
fact[0]=fact[1]=1;
fact[2]=2;
fact[3]=6;
fact[4]=24;
for(int i=1;i<=n;i++)
{
string a;
cin>>a;
setik.insert(a);
reverse(a.begin(),a.end());
setik.insert(a);
}
for(string s:setik)
{
int lg=s.size();
int x=toint(s[0]);
int y=toint(s[lg-1]);
nr[lg][x][y]++;
found[lg]=1;
}
for(int sz=3;sz<=10;sz++)
{
if(!found[sz])
continue;
found[sz]=0;
for(int t=1;t<=lgalph;t++)
{
for(int x=1;x<=lgalph;x++)
{
if(nr[sz][x][t]==0)
continue;
for(int y=x;y<=lgalph;y++)
{
if(nr[sz][y][t]==0)
continue;
for(int z=y;z<=lgalph;z++)
{
if(nr[sz][z][t]==0)
continue;
int h=gethash(x,y,z);
int sol=(1LL*nr[sz][x][t]*nr[sz][y][t])%mod;
sol=(1LL*sol*nr[sz][z][t])%mod;
coef[sz][h]=(coef[sz][h]+sol)%mod;
if(coef[sz][h]!=0)
found[sz]=1;
}
}
}
}
}
for(int sz=3;sz<=10;sz++)
{
if(!found[sz])
continue;
for(val[1]=1;val[1]<=lgalph;val[1]++)
for(val[3]=val[1];val[3]<=lgalph;val[3]++)
for(val[6]=val[3];val[6]<=lgalph;val[6]++)
{
int h=gethash(val[1],val[3],val[6]);
if(coef[sz][h]==0)
continue;
for(val[8]=val[6];val[8]<=lgalph;val[8]++)
{
int sol=1;
int x=gethash(val[1],val[3],val[6]);
sol=(1LL*sol*coef[sz][x])%mod;
x=gethash(val[1],val[3],val[8]);
sol=(1LL*sol*coef[sz][x])%mod;
x=gethash(val[1],val[6],val[8]);
sol=(1LL*sol*coef[sz][x])%mod;
x=gethash(val[3],val[6],val[8]);
sol=(1LL*sol*coef[sz][x])%mod;
sol=(1LL*sol*repperm(val[1],val[3],val[6],val[8]))%mod;
ans=(ans+sol)%mod;
}
}
}
cout<<ans;
return 0;
}
Compilation message
cubeword.cpp: In function 'int toint(char)':
cubeword.cpp:20:1: warning: control reaches end of non-void function [-Wreturn-type]
20 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
15880 KB |
Output is correct |
2 |
Correct |
162 ms |
15820 KB |
Output is correct |
3 |
Correct |
130 ms |
15944 KB |
Output is correct |
4 |
Correct |
131 ms |
15932 KB |
Output is correct |
5 |
Correct |
162 ms |
15948 KB |
Output is correct |
6 |
Correct |
138 ms |
15880 KB |
Output is correct |
7 |
Correct |
137 ms |
15944 KB |
Output is correct |
8 |
Correct |
129 ms |
15892 KB |
Output is correct |
9 |
Correct |
133 ms |
15944 KB |
Output is correct |
10 |
Correct |
153 ms |
15852 KB |
Output is correct |
11 |
Correct |
129 ms |
15888 KB |
Output is correct |
12 |
Correct |
132 ms |
15840 KB |
Output is correct |
13 |
Correct |
148 ms |
15904 KB |
Output is correct |
14 |
Correct |
150 ms |
15952 KB |
Output is correct |
15 |
Correct |
146 ms |
15944 KB |
Output is correct |
16 |
Correct |
132 ms |
15892 KB |
Output is correct |
17 |
Correct |
163 ms |
15948 KB |
Output is correct |
18 |
Correct |
129 ms |
15932 KB |
Output is correct |
19 |
Correct |
128 ms |
15816 KB |
Output is correct |
20 |
Correct |
165 ms |
15860 KB |
Output is correct |
21 |
Correct |
139 ms |
15928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
15880 KB |
Output is correct |
2 |
Correct |
162 ms |
15820 KB |
Output is correct |
3 |
Correct |
130 ms |
15944 KB |
Output is correct |
4 |
Correct |
131 ms |
15932 KB |
Output is correct |
5 |
Correct |
162 ms |
15948 KB |
Output is correct |
6 |
Correct |
138 ms |
15880 KB |
Output is correct |
7 |
Correct |
137 ms |
15944 KB |
Output is correct |
8 |
Correct |
129 ms |
15892 KB |
Output is correct |
9 |
Correct |
133 ms |
15944 KB |
Output is correct |
10 |
Correct |
153 ms |
15852 KB |
Output is correct |
11 |
Correct |
129 ms |
15888 KB |
Output is correct |
12 |
Correct |
132 ms |
15840 KB |
Output is correct |
13 |
Correct |
148 ms |
15904 KB |
Output is correct |
14 |
Correct |
150 ms |
15952 KB |
Output is correct |
15 |
Correct |
146 ms |
15944 KB |
Output is correct |
16 |
Correct |
132 ms |
15892 KB |
Output is correct |
17 |
Correct |
163 ms |
15948 KB |
Output is correct |
18 |
Correct |
129 ms |
15932 KB |
Output is correct |
19 |
Correct |
128 ms |
15816 KB |
Output is correct |
20 |
Correct |
165 ms |
15860 KB |
Output is correct |
21 |
Correct |
139 ms |
15928 KB |
Output is correct |
22 |
Correct |
134 ms |
17092 KB |
Output is correct |
23 |
Correct |
154 ms |
17040 KB |
Output is correct |
24 |
Correct |
184 ms |
17048 KB |
Output is correct |
25 |
Correct |
136 ms |
17088 KB |
Output is correct |
26 |
Correct |
161 ms |
17080 KB |
Output is correct |
27 |
Correct |
151 ms |
16968 KB |
Output is correct |
28 |
Correct |
145 ms |
17068 KB |
Output is correct |
29 |
Correct |
151 ms |
16988 KB |
Output is correct |
30 |
Correct |
153 ms |
17004 KB |
Output is correct |
31 |
Correct |
167 ms |
17060 KB |
Output is correct |
32 |
Correct |
136 ms |
17000 KB |
Output is correct |
33 |
Correct |
149 ms |
16976 KB |
Output is correct |
34 |
Correct |
147 ms |
16964 KB |
Output is correct |
35 |
Correct |
150 ms |
16972 KB |
Output is correct |
36 |
Correct |
187 ms |
17080 KB |
Output is correct |
37 |
Correct |
141 ms |
17080 KB |
Output is correct |
38 |
Correct |
154 ms |
16984 KB |
Output is correct |
39 |
Correct |
163 ms |
17084 KB |
Output is correct |
40 |
Correct |
166 ms |
17080 KB |
Output is correct |
41 |
Correct |
151 ms |
17024 KB |
Output is correct |
42 |
Correct |
144 ms |
17060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
15880 KB |
Output is correct |
2 |
Correct |
162 ms |
15820 KB |
Output is correct |
3 |
Correct |
130 ms |
15944 KB |
Output is correct |
4 |
Correct |
131 ms |
15932 KB |
Output is correct |
5 |
Correct |
162 ms |
15948 KB |
Output is correct |
6 |
Correct |
138 ms |
15880 KB |
Output is correct |
7 |
Correct |
137 ms |
15944 KB |
Output is correct |
8 |
Correct |
129 ms |
15892 KB |
Output is correct |
9 |
Correct |
133 ms |
15944 KB |
Output is correct |
10 |
Correct |
153 ms |
15852 KB |
Output is correct |
11 |
Correct |
129 ms |
15888 KB |
Output is correct |
12 |
Correct |
132 ms |
15840 KB |
Output is correct |
13 |
Correct |
148 ms |
15904 KB |
Output is correct |
14 |
Correct |
150 ms |
15952 KB |
Output is correct |
15 |
Correct |
146 ms |
15944 KB |
Output is correct |
16 |
Correct |
132 ms |
15892 KB |
Output is correct |
17 |
Correct |
163 ms |
15948 KB |
Output is correct |
18 |
Correct |
129 ms |
15932 KB |
Output is correct |
19 |
Correct |
128 ms |
15816 KB |
Output is correct |
20 |
Correct |
165 ms |
15860 KB |
Output is correct |
21 |
Correct |
139 ms |
15928 KB |
Output is correct |
22 |
Correct |
134 ms |
17092 KB |
Output is correct |
23 |
Correct |
154 ms |
17040 KB |
Output is correct |
24 |
Correct |
184 ms |
17048 KB |
Output is correct |
25 |
Correct |
136 ms |
17088 KB |
Output is correct |
26 |
Correct |
161 ms |
17080 KB |
Output is correct |
27 |
Correct |
151 ms |
16968 KB |
Output is correct |
28 |
Correct |
145 ms |
17068 KB |
Output is correct |
29 |
Correct |
151 ms |
16988 KB |
Output is correct |
30 |
Correct |
153 ms |
17004 KB |
Output is correct |
31 |
Correct |
167 ms |
17060 KB |
Output is correct |
32 |
Correct |
136 ms |
17000 KB |
Output is correct |
33 |
Correct |
149 ms |
16976 KB |
Output is correct |
34 |
Correct |
147 ms |
16964 KB |
Output is correct |
35 |
Correct |
150 ms |
16972 KB |
Output is correct |
36 |
Correct |
187 ms |
17080 KB |
Output is correct |
37 |
Correct |
141 ms |
17080 KB |
Output is correct |
38 |
Correct |
154 ms |
16984 KB |
Output is correct |
39 |
Correct |
163 ms |
17084 KB |
Output is correct |
40 |
Correct |
166 ms |
17080 KB |
Output is correct |
41 |
Correct |
151 ms |
17024 KB |
Output is correct |
42 |
Correct |
144 ms |
17060 KB |
Output is correct |
43 |
Correct |
171 ms |
18824 KB |
Output is correct |
44 |
Correct |
211 ms |
18908 KB |
Output is correct |
45 |
Correct |
158 ms |
18832 KB |
Output is correct |
46 |
Correct |
163 ms |
18992 KB |
Output is correct |
47 |
Correct |
187 ms |
18896 KB |
Output is correct |
48 |
Correct |
162 ms |
18900 KB |
Output is correct |
49 |
Correct |
161 ms |
18888 KB |
Output is correct |
50 |
Correct |
178 ms |
18804 KB |
Output is correct |
51 |
Correct |
167 ms |
18956 KB |
Output is correct |
52 |
Correct |
164 ms |
18900 KB |
Output is correct |
53 |
Correct |
196 ms |
18904 KB |
Output is correct |
54 |
Correct |
164 ms |
18888 KB |
Output is correct |
55 |
Correct |
163 ms |
18844 KB |
Output is correct |
56 |
Correct |
180 ms |
18888 KB |
Output is correct |
57 |
Correct |
155 ms |
18852 KB |
Output is correct |
58 |
Correct |
176 ms |
18796 KB |
Output is correct |
59 |
Correct |
181 ms |
18832 KB |
Output is correct |
60 |
Correct |
167 ms |
18824 KB |
Output is correct |
61 |
Correct |
178 ms |
18800 KB |
Output is correct |
62 |
Correct |
178 ms |
18844 KB |
Output is correct |
63 |
Correct |
168 ms |
18908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
15880 KB |
Output is correct |
2 |
Correct |
162 ms |
15820 KB |
Output is correct |
3 |
Correct |
130 ms |
15944 KB |
Output is correct |
4 |
Correct |
131 ms |
15932 KB |
Output is correct |
5 |
Correct |
162 ms |
15948 KB |
Output is correct |
6 |
Correct |
138 ms |
15880 KB |
Output is correct |
7 |
Correct |
137 ms |
15944 KB |
Output is correct |
8 |
Correct |
129 ms |
15892 KB |
Output is correct |
9 |
Correct |
133 ms |
15944 KB |
Output is correct |
10 |
Correct |
153 ms |
15852 KB |
Output is correct |
11 |
Correct |
129 ms |
15888 KB |
Output is correct |
12 |
Correct |
132 ms |
15840 KB |
Output is correct |
13 |
Correct |
148 ms |
15904 KB |
Output is correct |
14 |
Correct |
150 ms |
15952 KB |
Output is correct |
15 |
Correct |
146 ms |
15944 KB |
Output is correct |
16 |
Correct |
132 ms |
15892 KB |
Output is correct |
17 |
Correct |
163 ms |
15948 KB |
Output is correct |
18 |
Correct |
129 ms |
15932 KB |
Output is correct |
19 |
Correct |
128 ms |
15816 KB |
Output is correct |
20 |
Correct |
165 ms |
15860 KB |
Output is correct |
21 |
Correct |
139 ms |
15928 KB |
Output is correct |
22 |
Correct |
134 ms |
17092 KB |
Output is correct |
23 |
Correct |
154 ms |
17040 KB |
Output is correct |
24 |
Correct |
184 ms |
17048 KB |
Output is correct |
25 |
Correct |
136 ms |
17088 KB |
Output is correct |
26 |
Correct |
161 ms |
17080 KB |
Output is correct |
27 |
Correct |
151 ms |
16968 KB |
Output is correct |
28 |
Correct |
145 ms |
17068 KB |
Output is correct |
29 |
Correct |
151 ms |
16988 KB |
Output is correct |
30 |
Correct |
153 ms |
17004 KB |
Output is correct |
31 |
Correct |
167 ms |
17060 KB |
Output is correct |
32 |
Correct |
136 ms |
17000 KB |
Output is correct |
33 |
Correct |
149 ms |
16976 KB |
Output is correct |
34 |
Correct |
147 ms |
16964 KB |
Output is correct |
35 |
Correct |
150 ms |
16972 KB |
Output is correct |
36 |
Correct |
187 ms |
17080 KB |
Output is correct |
37 |
Correct |
141 ms |
17080 KB |
Output is correct |
38 |
Correct |
154 ms |
16984 KB |
Output is correct |
39 |
Correct |
163 ms |
17084 KB |
Output is correct |
40 |
Correct |
166 ms |
17080 KB |
Output is correct |
41 |
Correct |
151 ms |
17024 KB |
Output is correct |
42 |
Correct |
144 ms |
17060 KB |
Output is correct |
43 |
Correct |
171 ms |
18824 KB |
Output is correct |
44 |
Correct |
211 ms |
18908 KB |
Output is correct |
45 |
Correct |
158 ms |
18832 KB |
Output is correct |
46 |
Correct |
163 ms |
18992 KB |
Output is correct |
47 |
Correct |
187 ms |
18896 KB |
Output is correct |
48 |
Correct |
162 ms |
18900 KB |
Output is correct |
49 |
Correct |
161 ms |
18888 KB |
Output is correct |
50 |
Correct |
178 ms |
18804 KB |
Output is correct |
51 |
Correct |
167 ms |
18956 KB |
Output is correct |
52 |
Correct |
164 ms |
18900 KB |
Output is correct |
53 |
Correct |
196 ms |
18904 KB |
Output is correct |
54 |
Correct |
164 ms |
18888 KB |
Output is correct |
55 |
Correct |
163 ms |
18844 KB |
Output is correct |
56 |
Correct |
180 ms |
18888 KB |
Output is correct |
57 |
Correct |
155 ms |
18852 KB |
Output is correct |
58 |
Correct |
176 ms |
18796 KB |
Output is correct |
59 |
Correct |
181 ms |
18832 KB |
Output is correct |
60 |
Correct |
167 ms |
18824 KB |
Output is correct |
61 |
Correct |
178 ms |
18800 KB |
Output is correct |
62 |
Correct |
178 ms |
18844 KB |
Output is correct |
63 |
Correct |
168 ms |
18908 KB |
Output is correct |
64 |
Correct |
286 ms |
22368 KB |
Output is correct |
65 |
Correct |
320 ms |
22316 KB |
Output is correct |
66 |
Correct |
293 ms |
22364 KB |
Output is correct |
67 |
Correct |
298 ms |
22484 KB |
Output is correct |
68 |
Correct |
284 ms |
22364 KB |
Output is correct |
69 |
Correct |
329 ms |
22368 KB |
Output is correct |
70 |
Correct |
292 ms |
22252 KB |
Output is correct |
71 |
Correct |
280 ms |
22336 KB |
Output is correct |
72 |
Correct |
284 ms |
22364 KB |
Output is correct |
73 |
Correct |
280 ms |
22492 KB |
Output is correct |
74 |
Correct |
272 ms |
22296 KB |
Output is correct |
75 |
Correct |
322 ms |
22344 KB |
Output is correct |
76 |
Correct |
295 ms |
22356 KB |
Output is correct |
77 |
Correct |
292 ms |
22356 KB |
Output is correct |
78 |
Correct |
272 ms |
22364 KB |
Output is correct |
79 |
Correct |
268 ms |
22360 KB |
Output is correct |
80 |
Correct |
298 ms |
22296 KB |
Output is correct |
81 |
Correct |
265 ms |
22356 KB |
Output is correct |
82 |
Correct |
294 ms |
22356 KB |
Output is correct |
83 |
Correct |
266 ms |
22312 KB |
Output is correct |
84 |
Correct |
316 ms |
22336 KB |
Output is correct |