#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXK=62;
const int MAXN=1e5+6;
map<char,int>mp;
const ll mod=998244353;
string s[MAXN];
int cnt[100][100];
int ans=0,n;
int dp[100][100][100];
void solve(int d)
{
memset(cnt,0,sizeof(cnt));
memset(dp,0,sizeof(dp));
set<string>used;
for(int i=0;i<n;i++)
{
if(s[i].size()!=d)continue;
if(used.find(s[i])==used.end())
{
used.insert(s[i]);
cnt[mp[s[i][0]]][mp[s[i][s[i].size()-1]]]++;
}
reverse(s[i].begin(),s[i].end());
if(used.find(s[i])==used.end())
{
used.insert(s[i]);
cnt[mp[s[i][0]]][mp[s[i][s[i].size()-1]]]++;
}
reverse(s[i].begin(),s[i].end());
}
if(used.size()==0)return;
//cout<<d<<endl;
for(int i1=1;i1<=MAXK;i1++)
{
for(int i2=1;i2<=MAXK;i2++)
{
for(int i3=1;i3<=MAXK;i3++)
{
if(i2<i1||i3<i1||i3<i2)
{
int mn=min(i1,min(i2,i3));
int mx=max(i1,max(i2,i3));
dp[i1][i2][i3]=dp[mn][i1+i2+i3-mn-mx][mx];
}
else
{
for(int j=1;j<=MAXK;j++)
{
dp[i1][i2][i3]=dp[i1][i2][i3]+((ll)((ll)cnt[j][i1]*cnt[j][i2])%mod*cnt[j][i3])%mod;
dp[i1][i2][i3]%=mod;
}
}
}
}
}
for(int i1=1;i1<=MAXK;i1++)
{
for(int i2=i1;i2<=MAXK;i2++)
{
for(int i3=i2;i3<=MAXK;i3++)
{
for(int i4=i3;i4<=MAXK;i4++)
{
ll c;
if(i1==i2)
{
if(i2==i3)
{
if(i3==i4)c=1;
else c=4;
}
else
{
if(i3==i4)c=6;
else c=12;
}
}
else
{
if(i2==i3)
{
if(i3==i4)c=4;
else c=12;
}
else
{
if(i3==i4)c=12;
else c=24;
}
}
ans=ans+((ll)c*(((ll)(((ll)(((ll)dp[i1][i2][i3]*dp[i1][i2][i4])%mod)*dp[i1][i3][i4])%mod)*dp[i2][i3][i4])%mod))%mod;
ans%=mod;
}
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
for(char c='a';c<='z';c++)mp[c]=c-'a'+1;
for(char c='A';c<='Z';c++)mp[c]=c-'A'+27;
for(char c='0';c<='9';c++)mp[c]=c-'0'+53;
cin>>n;
for(int i=0;i<n;i++)cin>>s[i];
for(int i=3;i<=10;i++)
{
solve(i);
}
cout<<ans<<endl;
return 0;
}
Compilation message
cubeword.cpp: In function 'void solve(int)':
cubeword.cpp:19:17: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
19 | if(s[i].size()!=d)continue;
| ~~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
369 ms |
10476 KB |
Output is correct |
2 |
Correct |
378 ms |
10476 KB |
Output is correct |
3 |
Correct |
368 ms |
10476 KB |
Output is correct |
4 |
Correct |
369 ms |
10476 KB |
Output is correct |
5 |
Correct |
371 ms |
10476 KB |
Output is correct |
6 |
Correct |
366 ms |
10348 KB |
Output is correct |
7 |
Correct |
371 ms |
10476 KB |
Output is correct |
8 |
Correct |
383 ms |
10476 KB |
Output is correct |
9 |
Correct |
372 ms |
10364 KB |
Output is correct |
10 |
Correct |
368 ms |
10476 KB |
Output is correct |
11 |
Correct |
365 ms |
10476 KB |
Output is correct |
12 |
Correct |
366 ms |
10348 KB |
Output is correct |
13 |
Correct |
368 ms |
10476 KB |
Output is correct |
14 |
Correct |
367 ms |
10348 KB |
Output is correct |
15 |
Correct |
367 ms |
10400 KB |
Output is correct |
16 |
Correct |
364 ms |
10548 KB |
Output is correct |
17 |
Correct |
365 ms |
10604 KB |
Output is correct |
18 |
Correct |
363 ms |
10476 KB |
Output is correct |
19 |
Correct |
365 ms |
10476 KB |
Output is correct |
20 |
Correct |
368 ms |
10476 KB |
Output is correct |
21 |
Correct |
371 ms |
10476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
369 ms |
10476 KB |
Output is correct |
2 |
Correct |
378 ms |
10476 KB |
Output is correct |
3 |
Correct |
368 ms |
10476 KB |
Output is correct |
4 |
Correct |
369 ms |
10476 KB |
Output is correct |
5 |
Correct |
371 ms |
10476 KB |
Output is correct |
6 |
Correct |
366 ms |
10348 KB |
Output is correct |
7 |
Correct |
371 ms |
10476 KB |
Output is correct |
8 |
Correct |
383 ms |
10476 KB |
Output is correct |
9 |
Correct |
372 ms |
10364 KB |
Output is correct |
10 |
Correct |
368 ms |
10476 KB |
Output is correct |
11 |
Correct |
365 ms |
10476 KB |
Output is correct |
12 |
Correct |
366 ms |
10348 KB |
Output is correct |
13 |
Correct |
368 ms |
10476 KB |
Output is correct |
14 |
Correct |
367 ms |
10348 KB |
Output is correct |
15 |
Correct |
367 ms |
10400 KB |
Output is correct |
16 |
Correct |
364 ms |
10548 KB |
Output is correct |
17 |
Correct |
365 ms |
10604 KB |
Output is correct |
18 |
Correct |
363 ms |
10476 KB |
Output is correct |
19 |
Correct |
365 ms |
10476 KB |
Output is correct |
20 |
Correct |
368 ms |
10476 KB |
Output is correct |
21 |
Correct |
371 ms |
10476 KB |
Output is correct |
22 |
Correct |
362 ms |
9580 KB |
Output is correct |
23 |
Correct |
383 ms |
9708 KB |
Output is correct |
24 |
Correct |
359 ms |
9580 KB |
Output is correct |
25 |
Correct |
360 ms |
9580 KB |
Output is correct |
26 |
Correct |
366 ms |
9580 KB |
Output is correct |
27 |
Correct |
357 ms |
9580 KB |
Output is correct |
28 |
Correct |
359 ms |
9600 KB |
Output is correct |
29 |
Correct |
364 ms |
9580 KB |
Output is correct |
30 |
Correct |
363 ms |
9580 KB |
Output is correct |
31 |
Correct |
362 ms |
9708 KB |
Output is correct |
32 |
Correct |
358 ms |
9708 KB |
Output is correct |
33 |
Correct |
367 ms |
9708 KB |
Output is correct |
34 |
Correct |
358 ms |
9580 KB |
Output is correct |
35 |
Correct |
363 ms |
9580 KB |
Output is correct |
36 |
Correct |
356 ms |
9580 KB |
Output is correct |
37 |
Correct |
360 ms |
9580 KB |
Output is correct |
38 |
Correct |
365 ms |
9580 KB |
Output is correct |
39 |
Correct |
367 ms |
9612 KB |
Output is correct |
40 |
Correct |
362 ms |
9580 KB |
Output is correct |
41 |
Correct |
382 ms |
9708 KB |
Output is correct |
42 |
Correct |
367 ms |
9580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
369 ms |
10476 KB |
Output is correct |
2 |
Correct |
378 ms |
10476 KB |
Output is correct |
3 |
Correct |
368 ms |
10476 KB |
Output is correct |
4 |
Correct |
369 ms |
10476 KB |
Output is correct |
5 |
Correct |
371 ms |
10476 KB |
Output is correct |
6 |
Correct |
366 ms |
10348 KB |
Output is correct |
7 |
Correct |
371 ms |
10476 KB |
Output is correct |
8 |
Correct |
383 ms |
10476 KB |
Output is correct |
9 |
Correct |
372 ms |
10364 KB |
Output is correct |
10 |
Correct |
368 ms |
10476 KB |
Output is correct |
11 |
Correct |
365 ms |
10476 KB |
Output is correct |
12 |
Correct |
366 ms |
10348 KB |
Output is correct |
13 |
Correct |
368 ms |
10476 KB |
Output is correct |
14 |
Correct |
367 ms |
10348 KB |
Output is correct |
15 |
Correct |
367 ms |
10400 KB |
Output is correct |
16 |
Correct |
364 ms |
10548 KB |
Output is correct |
17 |
Correct |
365 ms |
10604 KB |
Output is correct |
18 |
Correct |
363 ms |
10476 KB |
Output is correct |
19 |
Correct |
365 ms |
10476 KB |
Output is correct |
20 |
Correct |
368 ms |
10476 KB |
Output is correct |
21 |
Correct |
371 ms |
10476 KB |
Output is correct |
22 |
Correct |
362 ms |
9580 KB |
Output is correct |
23 |
Correct |
383 ms |
9708 KB |
Output is correct |
24 |
Correct |
359 ms |
9580 KB |
Output is correct |
25 |
Correct |
360 ms |
9580 KB |
Output is correct |
26 |
Correct |
366 ms |
9580 KB |
Output is correct |
27 |
Correct |
357 ms |
9580 KB |
Output is correct |
28 |
Correct |
359 ms |
9600 KB |
Output is correct |
29 |
Correct |
364 ms |
9580 KB |
Output is correct |
30 |
Correct |
363 ms |
9580 KB |
Output is correct |
31 |
Correct |
362 ms |
9708 KB |
Output is correct |
32 |
Correct |
358 ms |
9708 KB |
Output is correct |
33 |
Correct |
367 ms |
9708 KB |
Output is correct |
34 |
Correct |
358 ms |
9580 KB |
Output is correct |
35 |
Correct |
363 ms |
9580 KB |
Output is correct |
36 |
Correct |
356 ms |
9580 KB |
Output is correct |
37 |
Correct |
360 ms |
9580 KB |
Output is correct |
38 |
Correct |
365 ms |
9580 KB |
Output is correct |
39 |
Correct |
367 ms |
9612 KB |
Output is correct |
40 |
Correct |
362 ms |
9580 KB |
Output is correct |
41 |
Correct |
382 ms |
9708 KB |
Output is correct |
42 |
Correct |
367 ms |
9580 KB |
Output is correct |
43 |
Correct |
359 ms |
9656 KB |
Output is correct |
44 |
Correct |
364 ms |
9452 KB |
Output is correct |
45 |
Correct |
363 ms |
9452 KB |
Output is correct |
46 |
Correct |
360 ms |
9500 KB |
Output is correct |
47 |
Correct |
362 ms |
9452 KB |
Output is correct |
48 |
Correct |
361 ms |
9580 KB |
Output is correct |
49 |
Correct |
362 ms |
9580 KB |
Output is correct |
50 |
Correct |
367 ms |
9580 KB |
Output is correct |
51 |
Correct |
374 ms |
9580 KB |
Output is correct |
52 |
Correct |
364 ms |
9708 KB |
Output is correct |
53 |
Correct |
360 ms |
9580 KB |
Output is correct |
54 |
Correct |
367 ms |
9452 KB |
Output is correct |
55 |
Correct |
361 ms |
9580 KB |
Output is correct |
56 |
Correct |
365 ms |
9452 KB |
Output is correct |
57 |
Correct |
365 ms |
9452 KB |
Output is correct |
58 |
Correct |
359 ms |
9452 KB |
Output is correct |
59 |
Correct |
361 ms |
9580 KB |
Output is correct |
60 |
Correct |
362 ms |
9580 KB |
Output is correct |
61 |
Correct |
372 ms |
9708 KB |
Output is correct |
62 |
Correct |
363 ms |
9580 KB |
Output is correct |
63 |
Correct |
361 ms |
9580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
369 ms |
10476 KB |
Output is correct |
2 |
Correct |
378 ms |
10476 KB |
Output is correct |
3 |
Correct |
368 ms |
10476 KB |
Output is correct |
4 |
Correct |
369 ms |
10476 KB |
Output is correct |
5 |
Correct |
371 ms |
10476 KB |
Output is correct |
6 |
Correct |
366 ms |
10348 KB |
Output is correct |
7 |
Correct |
371 ms |
10476 KB |
Output is correct |
8 |
Correct |
383 ms |
10476 KB |
Output is correct |
9 |
Correct |
372 ms |
10364 KB |
Output is correct |
10 |
Correct |
368 ms |
10476 KB |
Output is correct |
11 |
Correct |
365 ms |
10476 KB |
Output is correct |
12 |
Correct |
366 ms |
10348 KB |
Output is correct |
13 |
Correct |
368 ms |
10476 KB |
Output is correct |
14 |
Correct |
367 ms |
10348 KB |
Output is correct |
15 |
Correct |
367 ms |
10400 KB |
Output is correct |
16 |
Correct |
364 ms |
10548 KB |
Output is correct |
17 |
Correct |
365 ms |
10604 KB |
Output is correct |
18 |
Correct |
363 ms |
10476 KB |
Output is correct |
19 |
Correct |
365 ms |
10476 KB |
Output is correct |
20 |
Correct |
368 ms |
10476 KB |
Output is correct |
21 |
Correct |
371 ms |
10476 KB |
Output is correct |
22 |
Correct |
362 ms |
9580 KB |
Output is correct |
23 |
Correct |
383 ms |
9708 KB |
Output is correct |
24 |
Correct |
359 ms |
9580 KB |
Output is correct |
25 |
Correct |
360 ms |
9580 KB |
Output is correct |
26 |
Correct |
366 ms |
9580 KB |
Output is correct |
27 |
Correct |
357 ms |
9580 KB |
Output is correct |
28 |
Correct |
359 ms |
9600 KB |
Output is correct |
29 |
Correct |
364 ms |
9580 KB |
Output is correct |
30 |
Correct |
363 ms |
9580 KB |
Output is correct |
31 |
Correct |
362 ms |
9708 KB |
Output is correct |
32 |
Correct |
358 ms |
9708 KB |
Output is correct |
33 |
Correct |
367 ms |
9708 KB |
Output is correct |
34 |
Correct |
358 ms |
9580 KB |
Output is correct |
35 |
Correct |
363 ms |
9580 KB |
Output is correct |
36 |
Correct |
356 ms |
9580 KB |
Output is correct |
37 |
Correct |
360 ms |
9580 KB |
Output is correct |
38 |
Correct |
365 ms |
9580 KB |
Output is correct |
39 |
Correct |
367 ms |
9612 KB |
Output is correct |
40 |
Correct |
362 ms |
9580 KB |
Output is correct |
41 |
Correct |
382 ms |
9708 KB |
Output is correct |
42 |
Correct |
367 ms |
9580 KB |
Output is correct |
43 |
Correct |
359 ms |
9656 KB |
Output is correct |
44 |
Correct |
364 ms |
9452 KB |
Output is correct |
45 |
Correct |
363 ms |
9452 KB |
Output is correct |
46 |
Correct |
360 ms |
9500 KB |
Output is correct |
47 |
Correct |
362 ms |
9452 KB |
Output is correct |
48 |
Correct |
361 ms |
9580 KB |
Output is correct |
49 |
Correct |
362 ms |
9580 KB |
Output is correct |
50 |
Correct |
367 ms |
9580 KB |
Output is correct |
51 |
Correct |
374 ms |
9580 KB |
Output is correct |
52 |
Correct |
364 ms |
9708 KB |
Output is correct |
53 |
Correct |
360 ms |
9580 KB |
Output is correct |
54 |
Correct |
367 ms |
9452 KB |
Output is correct |
55 |
Correct |
361 ms |
9580 KB |
Output is correct |
56 |
Correct |
365 ms |
9452 KB |
Output is correct |
57 |
Correct |
365 ms |
9452 KB |
Output is correct |
58 |
Correct |
359 ms |
9452 KB |
Output is correct |
59 |
Correct |
361 ms |
9580 KB |
Output is correct |
60 |
Correct |
362 ms |
9580 KB |
Output is correct |
61 |
Correct |
372 ms |
9708 KB |
Output is correct |
62 |
Correct |
363 ms |
9580 KB |
Output is correct |
63 |
Correct |
361 ms |
9580 KB |
Output is correct |
64 |
Correct |
369 ms |
9580 KB |
Output is correct |
65 |
Correct |
364 ms |
10220 KB |
Output is correct |
66 |
Correct |
364 ms |
10092 KB |
Output is correct |
67 |
Correct |
367 ms |
10220 KB |
Output is correct |
68 |
Correct |
363 ms |
10348 KB |
Output is correct |
69 |
Correct |
366 ms |
10220 KB |
Output is correct |
70 |
Correct |
363 ms |
10220 KB |
Output is correct |
71 |
Correct |
362 ms |
10092 KB |
Output is correct |
72 |
Correct |
360 ms |
10220 KB |
Output is correct |
73 |
Correct |
370 ms |
10220 KB |
Output is correct |
74 |
Correct |
362 ms |
10220 KB |
Output is correct |
75 |
Correct |
364 ms |
10220 KB |
Output is correct |
76 |
Correct |
364 ms |
10220 KB |
Output is correct |
77 |
Correct |
363 ms |
10092 KB |
Output is correct |
78 |
Correct |
367 ms |
10308 KB |
Output is correct |
79 |
Correct |
368 ms |
10220 KB |
Output is correct |
80 |
Correct |
366 ms |
10348 KB |
Output is correct |
81 |
Correct |
361 ms |
10220 KB |
Output is correct |
82 |
Correct |
367 ms |
10244 KB |
Output is correct |
83 |
Correct |
375 ms |
10220 KB |
Output is correct |
84 |
Correct |
362 ms |
10220 KB |
Output is correct |