#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
const int MAXS = 62;
const ll MOD = 998244353;
int N;
ll ans, cnt[70][70], D[70][70][70];
vector<string> S, T[15];
int convert(char s)
{
if('a'<=s && s<='z') return s-'a';
if('A'<=s && s<='Z') return s-'A'+26;
if('0'<=s && s<='9') return s-'0'+52;
}
int main()
{
int i, j, p, q, k;
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin>>N;
for(i=1; i<=N; i++)
{
string s, t;
cin>>s; t=s;
reverse(t.begin(), t.end());
S.push_back(s);
S.push_back(t);
}
sort(S.begin(), S.end());
S.erase(unique(S.begin(), S.end()), S.end());
for(i=0; i<S.size(); i++) T[S[i].size()].push_back(S[i]);
for(k=3; k<=10; k++)
{
vector<string> V=T[k];
if(V.empty()) continue;
for(i=0; i<MAXS; i++) for(j=0; j<MAXS; j++) cnt[i][j]=0;
for(i=0; i<V.size(); i++) cnt[convert(V[i][0])][convert(V[i][V[i].size()-1])]++;
for(i=0; i<MAXS; i++) for(j=i; j<MAXS; j++) for(p=j; p<MAXS; p++)
{
D[i][j][p]=0;
for(q=0; q<MAXS; q++)
{
D[i][j][p]+=cnt[i][q]*cnt[j][q]%MOD*cnt[p][q]%MOD;
D[i][j][p]%=MOD;
}
}
for(i=0; i<MAXS; i++) for(j=i+1; j<MAXS; j++) for(p=j+1; p<MAXS; p++) for(q=p+1; q<MAXS; q++)
{
ans+=24*D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD;
ans%=MOD;
}
for(i=0; i<MAXS; i++) for(j=i, p=j+1; p<MAXS; p++) for(q=p+1; q<MAXS; q++)
{
ans+=12*D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD;
ans%=MOD;
}
for(i=0; i<MAXS; i++) for(j=i+1; j<MAXS; j++) for(p=j, q=p+1; q<MAXS; q++)
{
ans+=12*D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD;
ans%=MOD;
}
for(i=0; i<MAXS; i++) for(j=i+1; j<MAXS; j++) for(p=j+1; p<MAXS; p++)
{
q=p;
ans+=12*D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD;
ans%=MOD;
}
for(i=0; i<MAXS; i++) for(j=i, p=j+1; p<MAXS; p++)
{
q=p;
ans+=6*D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD;
ans%=MOD;
}
for(i=0; i<MAXS; i++) for(j=i+1; j<MAXS; j++)
{
p=q=j;
ans+=4*D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD;
ans%=MOD;
}
for(i=0; i<MAXS; i++) for(j=p=i, q=p+1; q<MAXS; q++)
{
ans+=4*D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD;
ans%=MOD;
}
for(i=0; i<MAXS; i++)
{
j=p=q=i;
ans+=D[i][j][p]%MOD*D[i][j][q]%MOD*D[i][p][q]%MOD*D[j][p][q]%MOD;
ans%=MOD;
}
}
cout<<ans;
}
Compilation message
cubeword.cpp: In function 'int main()':
cubeword.cpp:42:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0; i<S.size(); i++) T[S[i].size()].push_back(S[i]);
~^~~~~~~~~
cubeword.cpp:50:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0; i<V.size(); i++) cnt[convert(V[i][0])][convert(V[i][V[i].size()-1])]++;
~^~~~~~~~~
cubeword.cpp: In function 'int convert(char)':
cubeword.cpp:21:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
330 ms |
18516 KB |
Output is correct |
2 |
Correct |
337 ms |
17336 KB |
Output is correct |
3 |
Correct |
330 ms |
18568 KB |
Output is correct |
4 |
Correct |
326 ms |
19156 KB |
Output is correct |
5 |
Correct |
315 ms |
18520 KB |
Output is correct |
6 |
Correct |
327 ms |
18260 KB |
Output is correct |
7 |
Correct |
310 ms |
18260 KB |
Output is correct |
8 |
Correct |
326 ms |
18132 KB |
Output is correct |
9 |
Correct |
332 ms |
19156 KB |
Output is correct |
10 |
Correct |
311 ms |
18516 KB |
Output is correct |
11 |
Correct |
326 ms |
18132 KB |
Output is correct |
12 |
Correct |
310 ms |
17876 KB |
Output is correct |
13 |
Correct |
308 ms |
17752 KB |
Output is correct |
14 |
Correct |
320 ms |
18772 KB |
Output is correct |
15 |
Correct |
327 ms |
18132 KB |
Output is correct |
16 |
Correct |
329 ms |
18792 KB |
Output is correct |
17 |
Correct |
317 ms |
18108 KB |
Output is correct |
18 |
Correct |
333 ms |
18108 KB |
Output is correct |
19 |
Correct |
324 ms |
17492 KB |
Output is correct |
20 |
Correct |
326 ms |
18880 KB |
Output is correct |
21 |
Correct |
314 ms |
17852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
330 ms |
18516 KB |
Output is correct |
2 |
Correct |
337 ms |
17336 KB |
Output is correct |
3 |
Correct |
330 ms |
18568 KB |
Output is correct |
4 |
Correct |
326 ms |
19156 KB |
Output is correct |
5 |
Correct |
315 ms |
18520 KB |
Output is correct |
6 |
Correct |
327 ms |
18260 KB |
Output is correct |
7 |
Correct |
310 ms |
18260 KB |
Output is correct |
8 |
Correct |
326 ms |
18132 KB |
Output is correct |
9 |
Correct |
332 ms |
19156 KB |
Output is correct |
10 |
Correct |
311 ms |
18516 KB |
Output is correct |
11 |
Correct |
326 ms |
18132 KB |
Output is correct |
12 |
Correct |
310 ms |
17876 KB |
Output is correct |
13 |
Correct |
308 ms |
17752 KB |
Output is correct |
14 |
Correct |
320 ms |
18772 KB |
Output is correct |
15 |
Correct |
327 ms |
18132 KB |
Output is correct |
16 |
Correct |
329 ms |
18792 KB |
Output is correct |
17 |
Correct |
317 ms |
18108 KB |
Output is correct |
18 |
Correct |
333 ms |
18108 KB |
Output is correct |
19 |
Correct |
324 ms |
17492 KB |
Output is correct |
20 |
Correct |
326 ms |
18880 KB |
Output is correct |
21 |
Correct |
314 ms |
17852 KB |
Output is correct |
22 |
Correct |
335 ms |
15572 KB |
Output is correct |
23 |
Correct |
309 ms |
16592 KB |
Output is correct |
24 |
Correct |
326 ms |
16596 KB |
Output is correct |
25 |
Correct |
331 ms |
17076 KB |
Output is correct |
26 |
Correct |
322 ms |
16904 KB |
Output is correct |
27 |
Correct |
318 ms |
17260 KB |
Output is correct |
28 |
Correct |
312 ms |
17624 KB |
Output is correct |
29 |
Correct |
331 ms |
17664 KB |
Output is correct |
30 |
Correct |
320 ms |
16980 KB |
Output is correct |
31 |
Correct |
330 ms |
16932 KB |
Output is correct |
32 |
Correct |
316 ms |
15700 KB |
Output is correct |
33 |
Correct |
323 ms |
16724 KB |
Output is correct |
34 |
Correct |
315 ms |
16852 KB |
Output is correct |
35 |
Correct |
314 ms |
16852 KB |
Output is correct |
36 |
Correct |
319 ms |
15572 KB |
Output is correct |
37 |
Correct |
324 ms |
16596 KB |
Output is correct |
38 |
Correct |
349 ms |
16852 KB |
Output is correct |
39 |
Correct |
316 ms |
16908 KB |
Output is correct |
40 |
Correct |
310 ms |
15956 KB |
Output is correct |
41 |
Correct |
315 ms |
16468 KB |
Output is correct |
42 |
Correct |
318 ms |
16512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
330 ms |
18516 KB |
Output is correct |
2 |
Correct |
337 ms |
17336 KB |
Output is correct |
3 |
Correct |
330 ms |
18568 KB |
Output is correct |
4 |
Correct |
326 ms |
19156 KB |
Output is correct |
5 |
Correct |
315 ms |
18520 KB |
Output is correct |
6 |
Correct |
327 ms |
18260 KB |
Output is correct |
7 |
Correct |
310 ms |
18260 KB |
Output is correct |
8 |
Correct |
326 ms |
18132 KB |
Output is correct |
9 |
Correct |
332 ms |
19156 KB |
Output is correct |
10 |
Correct |
311 ms |
18516 KB |
Output is correct |
11 |
Correct |
326 ms |
18132 KB |
Output is correct |
12 |
Correct |
310 ms |
17876 KB |
Output is correct |
13 |
Correct |
308 ms |
17752 KB |
Output is correct |
14 |
Correct |
320 ms |
18772 KB |
Output is correct |
15 |
Correct |
327 ms |
18132 KB |
Output is correct |
16 |
Correct |
329 ms |
18792 KB |
Output is correct |
17 |
Correct |
317 ms |
18108 KB |
Output is correct |
18 |
Correct |
333 ms |
18108 KB |
Output is correct |
19 |
Correct |
324 ms |
17492 KB |
Output is correct |
20 |
Correct |
326 ms |
18880 KB |
Output is correct |
21 |
Correct |
314 ms |
17852 KB |
Output is correct |
22 |
Correct |
335 ms |
15572 KB |
Output is correct |
23 |
Correct |
309 ms |
16592 KB |
Output is correct |
24 |
Correct |
326 ms |
16596 KB |
Output is correct |
25 |
Correct |
331 ms |
17076 KB |
Output is correct |
26 |
Correct |
322 ms |
16904 KB |
Output is correct |
27 |
Correct |
318 ms |
17260 KB |
Output is correct |
28 |
Correct |
312 ms |
17624 KB |
Output is correct |
29 |
Correct |
331 ms |
17664 KB |
Output is correct |
30 |
Correct |
320 ms |
16980 KB |
Output is correct |
31 |
Correct |
330 ms |
16932 KB |
Output is correct |
32 |
Correct |
316 ms |
15700 KB |
Output is correct |
33 |
Correct |
323 ms |
16724 KB |
Output is correct |
34 |
Correct |
315 ms |
16852 KB |
Output is correct |
35 |
Correct |
314 ms |
16852 KB |
Output is correct |
36 |
Correct |
319 ms |
15572 KB |
Output is correct |
37 |
Correct |
324 ms |
16596 KB |
Output is correct |
38 |
Correct |
349 ms |
16852 KB |
Output is correct |
39 |
Correct |
316 ms |
16908 KB |
Output is correct |
40 |
Correct |
310 ms |
15956 KB |
Output is correct |
41 |
Correct |
315 ms |
16468 KB |
Output is correct |
42 |
Correct |
318 ms |
16512 KB |
Output is correct |
43 |
Correct |
319 ms |
17492 KB |
Output is correct |
44 |
Correct |
316 ms |
17292 KB |
Output is correct |
45 |
Correct |
317 ms |
17620 KB |
Output is correct |
46 |
Correct |
326 ms |
16912 KB |
Output is correct |
47 |
Correct |
313 ms |
17364 KB |
Output is correct |
48 |
Correct |
326 ms |
17492 KB |
Output is correct |
49 |
Correct |
309 ms |
16980 KB |
Output is correct |
50 |
Correct |
316 ms |
16724 KB |
Output is correct |
51 |
Correct |
314 ms |
16600 KB |
Output is correct |
52 |
Correct |
323 ms |
16848 KB |
Output is correct |
53 |
Correct |
312 ms |
17084 KB |
Output is correct |
54 |
Correct |
318 ms |
17108 KB |
Output is correct |
55 |
Correct |
319 ms |
16340 KB |
Output is correct |
56 |
Correct |
304 ms |
17108 KB |
Output is correct |
57 |
Correct |
328 ms |
17236 KB |
Output is correct |
58 |
Correct |
331 ms |
17040 KB |
Output is correct |
59 |
Correct |
318 ms |
16212 KB |
Output is correct |
60 |
Correct |
320 ms |
17620 KB |
Output is correct |
61 |
Correct |
318 ms |
16216 KB |
Output is correct |
62 |
Correct |
322 ms |
17108 KB |
Output is correct |
63 |
Correct |
314 ms |
16848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
330 ms |
18516 KB |
Output is correct |
2 |
Correct |
337 ms |
17336 KB |
Output is correct |
3 |
Correct |
330 ms |
18568 KB |
Output is correct |
4 |
Correct |
326 ms |
19156 KB |
Output is correct |
5 |
Correct |
315 ms |
18520 KB |
Output is correct |
6 |
Correct |
327 ms |
18260 KB |
Output is correct |
7 |
Correct |
310 ms |
18260 KB |
Output is correct |
8 |
Correct |
326 ms |
18132 KB |
Output is correct |
9 |
Correct |
332 ms |
19156 KB |
Output is correct |
10 |
Correct |
311 ms |
18516 KB |
Output is correct |
11 |
Correct |
326 ms |
18132 KB |
Output is correct |
12 |
Correct |
310 ms |
17876 KB |
Output is correct |
13 |
Correct |
308 ms |
17752 KB |
Output is correct |
14 |
Correct |
320 ms |
18772 KB |
Output is correct |
15 |
Correct |
327 ms |
18132 KB |
Output is correct |
16 |
Correct |
329 ms |
18792 KB |
Output is correct |
17 |
Correct |
317 ms |
18108 KB |
Output is correct |
18 |
Correct |
333 ms |
18108 KB |
Output is correct |
19 |
Correct |
324 ms |
17492 KB |
Output is correct |
20 |
Correct |
326 ms |
18880 KB |
Output is correct |
21 |
Correct |
314 ms |
17852 KB |
Output is correct |
22 |
Correct |
335 ms |
15572 KB |
Output is correct |
23 |
Correct |
309 ms |
16592 KB |
Output is correct |
24 |
Correct |
326 ms |
16596 KB |
Output is correct |
25 |
Correct |
331 ms |
17076 KB |
Output is correct |
26 |
Correct |
322 ms |
16904 KB |
Output is correct |
27 |
Correct |
318 ms |
17260 KB |
Output is correct |
28 |
Correct |
312 ms |
17624 KB |
Output is correct |
29 |
Correct |
331 ms |
17664 KB |
Output is correct |
30 |
Correct |
320 ms |
16980 KB |
Output is correct |
31 |
Correct |
330 ms |
16932 KB |
Output is correct |
32 |
Correct |
316 ms |
15700 KB |
Output is correct |
33 |
Correct |
323 ms |
16724 KB |
Output is correct |
34 |
Correct |
315 ms |
16852 KB |
Output is correct |
35 |
Correct |
314 ms |
16852 KB |
Output is correct |
36 |
Correct |
319 ms |
15572 KB |
Output is correct |
37 |
Correct |
324 ms |
16596 KB |
Output is correct |
38 |
Correct |
349 ms |
16852 KB |
Output is correct |
39 |
Correct |
316 ms |
16908 KB |
Output is correct |
40 |
Correct |
310 ms |
15956 KB |
Output is correct |
41 |
Correct |
315 ms |
16468 KB |
Output is correct |
42 |
Correct |
318 ms |
16512 KB |
Output is correct |
43 |
Correct |
319 ms |
17492 KB |
Output is correct |
44 |
Correct |
316 ms |
17292 KB |
Output is correct |
45 |
Correct |
317 ms |
17620 KB |
Output is correct |
46 |
Correct |
326 ms |
16912 KB |
Output is correct |
47 |
Correct |
313 ms |
17364 KB |
Output is correct |
48 |
Correct |
326 ms |
17492 KB |
Output is correct |
49 |
Correct |
309 ms |
16980 KB |
Output is correct |
50 |
Correct |
316 ms |
16724 KB |
Output is correct |
51 |
Correct |
314 ms |
16600 KB |
Output is correct |
52 |
Correct |
323 ms |
16848 KB |
Output is correct |
53 |
Correct |
312 ms |
17084 KB |
Output is correct |
54 |
Correct |
318 ms |
17108 KB |
Output is correct |
55 |
Correct |
319 ms |
16340 KB |
Output is correct |
56 |
Correct |
304 ms |
17108 KB |
Output is correct |
57 |
Correct |
328 ms |
17236 KB |
Output is correct |
58 |
Correct |
331 ms |
17040 KB |
Output is correct |
59 |
Correct |
318 ms |
16212 KB |
Output is correct |
60 |
Correct |
320 ms |
17620 KB |
Output is correct |
61 |
Correct |
318 ms |
16216 KB |
Output is correct |
62 |
Correct |
322 ms |
17108 KB |
Output is correct |
63 |
Correct |
314 ms |
16848 KB |
Output is correct |
64 |
Correct |
314 ms |
17112 KB |
Output is correct |
65 |
Correct |
314 ms |
17344 KB |
Output is correct |
66 |
Correct |
317 ms |
17108 KB |
Output is correct |
67 |
Correct |
307 ms |
17368 KB |
Output is correct |
68 |
Correct |
320 ms |
17112 KB |
Output is correct |
69 |
Correct |
313 ms |
16724 KB |
Output is correct |
70 |
Correct |
315 ms |
16976 KB |
Output is correct |
71 |
Correct |
314 ms |
17112 KB |
Output is correct |
72 |
Correct |
308 ms |
16980 KB |
Output is correct |
73 |
Correct |
316 ms |
17108 KB |
Output is correct |
74 |
Correct |
323 ms |
16468 KB |
Output is correct |
75 |
Correct |
320 ms |
17108 KB |
Output is correct |
76 |
Correct |
318 ms |
16852 KB |
Output is correct |
77 |
Correct |
318 ms |
16980 KB |
Output is correct |
78 |
Correct |
316 ms |
17360 KB |
Output is correct |
79 |
Correct |
322 ms |
17164 KB |
Output is correct |
80 |
Correct |
315 ms |
16984 KB |
Output is correct |
81 |
Correct |
315 ms |
17620 KB |
Output is correct |
82 |
Correct |
308 ms |
16468 KB |
Output is correct |
83 |
Correct |
316 ms |
17236 KB |
Output is correct |
84 |
Correct |
324 ms |
16852 KB |
Output is correct |