#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define rep(a,b,c) for(int a=b; a<c; a++)
#define rep2(a,b,c,d) for(ll a=b; a<c; a+=d)
#define repr(a,b,c) for(ll a=b-1; a>c-1; a--)
#define repa(a,b) for(const auto &a: b)
#define multicase() int t; cin>>t; while(t--)
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define valid(c) cout<<(c ? "YES" : "NO")<<endl;
#define valid2(c,a,b) cout<<(c ? a : b)<<endl;
#define ll long long
#define pq_min(a) priority_queue<a, vector<a>, greater<a>>
#define pq_max(a) priority_queue<a>
#define pb push_back
#define mid ((l+r)>>1)
#define flush endl<<flush;
using namespace std;
const ll mod=998244353;
ll ANS[11][62][62][62][62]{};
int main(){
fastIO();
int n;
cin>>n;
string s;
set<string> st;
ll t[11][62][62]{};
map<char,int> val;
rep(i,0,26){
val[i+'a']=i;
val[i+'A']=i+26;
}
rep(i,0,10) val[i+'0']=i+52;
rep(i,0,n){
cin>>s;
st.insert(s);
reverse(s.begin(),s.end());
st.insert(s);
}
repa(e,st) t[e.size()][val[e[0]]][val[e.back()]]++;
ll ans=0;
rep(z,3,11){
ll C[62][62][62]{};
rep(i,0,62) rep(j,i,62) rep(k,j,62) rep(l,0,62){
if(!t[i][l] || !t[k][l] || !t[j][l]) continue;
C[i][j][k]+=t[z][i][l]*t[z][j][l]%mod*t[z][k][l]%mod;
C[i][j][k]%=mod;
C[i][k][j]=C[j][i][k]=C[j][k][i]=C[k][i][j]=C[k][j][i]=C[i][j][k];
}
rep(i,0,62) rep(j,0,62) rep(k,0,62) rep(l,0,62){
if(!C[i][j][k] || !C[i][j][l] || !C[i][k][l] || !C[j][k][l]) continue;
int p[4]={i,j,k,l};
sort(p,p+4);
if(!ANS[z][p[0]][p[1]][p[2]][p[3]])
ANS[z][p[0]][p[1]][p[2]][p[3]]=C[i][j][k]*C[i][j][l]%mod*C[i][k][l]%mod*C[j][k][l]%mod;
ans+=ANS[z][p[0]][p[1]][p[2]][p[3]];
ans%=mod;
}
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
19036 KB |
Output is correct |
2 |
Correct |
263 ms |
19028 KB |
Output is correct |
3 |
Correct |
284 ms |
19024 KB |
Output is correct |
4 |
Correct |
275 ms |
19052 KB |
Output is correct |
5 |
Correct |
276 ms |
19032 KB |
Output is correct |
6 |
Correct |
290 ms |
19164 KB |
Output is correct |
7 |
Correct |
274 ms |
19028 KB |
Output is correct |
8 |
Correct |
273 ms |
19040 KB |
Output is correct |
9 |
Correct |
273 ms |
19028 KB |
Output is correct |
10 |
Correct |
264 ms |
19032 KB |
Output is correct |
11 |
Correct |
281 ms |
19032 KB |
Output is correct |
12 |
Correct |
269 ms |
18852 KB |
Output is correct |
13 |
Correct |
266 ms |
19028 KB |
Output is correct |
14 |
Correct |
285 ms |
19032 KB |
Output is correct |
15 |
Correct |
282 ms |
19024 KB |
Output is correct |
16 |
Correct |
272 ms |
18844 KB |
Output is correct |
17 |
Correct |
275 ms |
19028 KB |
Output is correct |
18 |
Correct |
262 ms |
19032 KB |
Output is correct |
19 |
Correct |
285 ms |
19028 KB |
Output is correct |
20 |
Correct |
276 ms |
18872 KB |
Output is correct |
21 |
Correct |
305 ms |
19024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
19036 KB |
Output is correct |
2 |
Correct |
263 ms |
19028 KB |
Output is correct |
3 |
Correct |
284 ms |
19024 KB |
Output is correct |
4 |
Correct |
275 ms |
19052 KB |
Output is correct |
5 |
Correct |
276 ms |
19032 KB |
Output is correct |
6 |
Correct |
290 ms |
19164 KB |
Output is correct |
7 |
Correct |
274 ms |
19028 KB |
Output is correct |
8 |
Correct |
273 ms |
19040 KB |
Output is correct |
9 |
Correct |
273 ms |
19028 KB |
Output is correct |
10 |
Correct |
264 ms |
19032 KB |
Output is correct |
11 |
Correct |
281 ms |
19032 KB |
Output is correct |
12 |
Correct |
269 ms |
18852 KB |
Output is correct |
13 |
Correct |
266 ms |
19028 KB |
Output is correct |
14 |
Correct |
285 ms |
19032 KB |
Output is correct |
15 |
Correct |
282 ms |
19024 KB |
Output is correct |
16 |
Correct |
272 ms |
18844 KB |
Output is correct |
17 |
Correct |
275 ms |
19028 KB |
Output is correct |
18 |
Correct |
262 ms |
19032 KB |
Output is correct |
19 |
Correct |
285 ms |
19028 KB |
Output is correct |
20 |
Correct |
276 ms |
18872 KB |
Output is correct |
21 |
Correct |
305 ms |
19024 KB |
Output is correct |
22 |
Correct |
292 ms |
25732 KB |
Output is correct |
23 |
Correct |
282 ms |
25680 KB |
Output is correct |
24 |
Correct |
277 ms |
25776 KB |
Output is correct |
25 |
Correct |
282 ms |
25680 KB |
Output is correct |
26 |
Correct |
298 ms |
25740 KB |
Output is correct |
27 |
Correct |
280 ms |
25684 KB |
Output is correct |
28 |
Correct |
302 ms |
25684 KB |
Output is correct |
29 |
Correct |
283 ms |
25684 KB |
Output is correct |
30 |
Correct |
277 ms |
25596 KB |
Output is correct |
31 |
Correct |
293 ms |
25696 KB |
Output is correct |
32 |
Correct |
276 ms |
25684 KB |
Output is correct |
33 |
Correct |
310 ms |
25644 KB |
Output is correct |
34 |
Correct |
310 ms |
25684 KB |
Output is correct |
35 |
Correct |
288 ms |
25792 KB |
Output is correct |
36 |
Correct |
298 ms |
25644 KB |
Output is correct |
37 |
Correct |
267 ms |
25816 KB |
Output is correct |
38 |
Correct |
300 ms |
25684 KB |
Output is correct |
39 |
Correct |
290 ms |
25684 KB |
Output is correct |
40 |
Correct |
310 ms |
25680 KB |
Output is correct |
41 |
Correct |
288 ms |
25808 KB |
Output is correct |
42 |
Correct |
300 ms |
25936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
19036 KB |
Output is correct |
2 |
Correct |
263 ms |
19028 KB |
Output is correct |
3 |
Correct |
284 ms |
19024 KB |
Output is correct |
4 |
Correct |
275 ms |
19052 KB |
Output is correct |
5 |
Correct |
276 ms |
19032 KB |
Output is correct |
6 |
Correct |
290 ms |
19164 KB |
Output is correct |
7 |
Correct |
274 ms |
19028 KB |
Output is correct |
8 |
Correct |
273 ms |
19040 KB |
Output is correct |
9 |
Correct |
273 ms |
19028 KB |
Output is correct |
10 |
Correct |
264 ms |
19032 KB |
Output is correct |
11 |
Correct |
281 ms |
19032 KB |
Output is correct |
12 |
Correct |
269 ms |
18852 KB |
Output is correct |
13 |
Correct |
266 ms |
19028 KB |
Output is correct |
14 |
Correct |
285 ms |
19032 KB |
Output is correct |
15 |
Correct |
282 ms |
19024 KB |
Output is correct |
16 |
Correct |
272 ms |
18844 KB |
Output is correct |
17 |
Correct |
275 ms |
19028 KB |
Output is correct |
18 |
Correct |
262 ms |
19032 KB |
Output is correct |
19 |
Correct |
285 ms |
19028 KB |
Output is correct |
20 |
Correct |
276 ms |
18872 KB |
Output is correct |
21 |
Correct |
305 ms |
19024 KB |
Output is correct |
22 |
Correct |
292 ms |
25732 KB |
Output is correct |
23 |
Correct |
282 ms |
25680 KB |
Output is correct |
24 |
Correct |
277 ms |
25776 KB |
Output is correct |
25 |
Correct |
282 ms |
25680 KB |
Output is correct |
26 |
Correct |
298 ms |
25740 KB |
Output is correct |
27 |
Correct |
280 ms |
25684 KB |
Output is correct |
28 |
Correct |
302 ms |
25684 KB |
Output is correct |
29 |
Correct |
283 ms |
25684 KB |
Output is correct |
30 |
Correct |
277 ms |
25596 KB |
Output is correct |
31 |
Correct |
293 ms |
25696 KB |
Output is correct |
32 |
Correct |
276 ms |
25684 KB |
Output is correct |
33 |
Correct |
310 ms |
25644 KB |
Output is correct |
34 |
Correct |
310 ms |
25684 KB |
Output is correct |
35 |
Correct |
288 ms |
25792 KB |
Output is correct |
36 |
Correct |
298 ms |
25644 KB |
Output is correct |
37 |
Correct |
267 ms |
25816 KB |
Output is correct |
38 |
Correct |
300 ms |
25684 KB |
Output is correct |
39 |
Correct |
290 ms |
25684 KB |
Output is correct |
40 |
Correct |
310 ms |
25680 KB |
Output is correct |
41 |
Correct |
288 ms |
25808 KB |
Output is correct |
42 |
Correct |
300 ms |
25936 KB |
Output is correct |
43 |
Correct |
443 ms |
62032 KB |
Output is correct |
44 |
Correct |
451 ms |
62096 KB |
Output is correct |
45 |
Correct |
420 ms |
62112 KB |
Output is correct |
46 |
Correct |
438 ms |
62036 KB |
Output is correct |
47 |
Correct |
458 ms |
62036 KB |
Output is correct |
48 |
Correct |
393 ms |
62028 KB |
Output is correct |
49 |
Correct |
420 ms |
62036 KB |
Output is correct |
50 |
Correct |
430 ms |
62136 KB |
Output is correct |
51 |
Correct |
449 ms |
62056 KB |
Output is correct |
52 |
Correct |
438 ms |
62036 KB |
Output is correct |
53 |
Correct |
440 ms |
62032 KB |
Output is correct |
54 |
Correct |
426 ms |
62036 KB |
Output is correct |
55 |
Correct |
444 ms |
62080 KB |
Output is correct |
56 |
Correct |
428 ms |
62116 KB |
Output is correct |
57 |
Correct |
439 ms |
61976 KB |
Output is correct |
58 |
Correct |
445 ms |
61996 KB |
Output is correct |
59 |
Correct |
430 ms |
62036 KB |
Output is correct |
60 |
Correct |
432 ms |
62064 KB |
Output is correct |
61 |
Correct |
434 ms |
61924 KB |
Output is correct |
62 |
Correct |
427 ms |
62036 KB |
Output is correct |
63 |
Correct |
421 ms |
62036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
19036 KB |
Output is correct |
2 |
Correct |
263 ms |
19028 KB |
Output is correct |
3 |
Correct |
284 ms |
19024 KB |
Output is correct |
4 |
Correct |
275 ms |
19052 KB |
Output is correct |
5 |
Correct |
276 ms |
19032 KB |
Output is correct |
6 |
Correct |
290 ms |
19164 KB |
Output is correct |
7 |
Correct |
274 ms |
19028 KB |
Output is correct |
8 |
Correct |
273 ms |
19040 KB |
Output is correct |
9 |
Correct |
273 ms |
19028 KB |
Output is correct |
10 |
Correct |
264 ms |
19032 KB |
Output is correct |
11 |
Correct |
281 ms |
19032 KB |
Output is correct |
12 |
Correct |
269 ms |
18852 KB |
Output is correct |
13 |
Correct |
266 ms |
19028 KB |
Output is correct |
14 |
Correct |
285 ms |
19032 KB |
Output is correct |
15 |
Correct |
282 ms |
19024 KB |
Output is correct |
16 |
Correct |
272 ms |
18844 KB |
Output is correct |
17 |
Correct |
275 ms |
19028 KB |
Output is correct |
18 |
Correct |
262 ms |
19032 KB |
Output is correct |
19 |
Correct |
285 ms |
19028 KB |
Output is correct |
20 |
Correct |
276 ms |
18872 KB |
Output is correct |
21 |
Correct |
305 ms |
19024 KB |
Output is correct |
22 |
Correct |
292 ms |
25732 KB |
Output is correct |
23 |
Correct |
282 ms |
25680 KB |
Output is correct |
24 |
Correct |
277 ms |
25776 KB |
Output is correct |
25 |
Correct |
282 ms |
25680 KB |
Output is correct |
26 |
Correct |
298 ms |
25740 KB |
Output is correct |
27 |
Correct |
280 ms |
25684 KB |
Output is correct |
28 |
Correct |
302 ms |
25684 KB |
Output is correct |
29 |
Correct |
283 ms |
25684 KB |
Output is correct |
30 |
Correct |
277 ms |
25596 KB |
Output is correct |
31 |
Correct |
293 ms |
25696 KB |
Output is correct |
32 |
Correct |
276 ms |
25684 KB |
Output is correct |
33 |
Correct |
310 ms |
25644 KB |
Output is correct |
34 |
Correct |
310 ms |
25684 KB |
Output is correct |
35 |
Correct |
288 ms |
25792 KB |
Output is correct |
36 |
Correct |
298 ms |
25644 KB |
Output is correct |
37 |
Correct |
267 ms |
25816 KB |
Output is correct |
38 |
Correct |
300 ms |
25684 KB |
Output is correct |
39 |
Correct |
290 ms |
25684 KB |
Output is correct |
40 |
Correct |
310 ms |
25680 KB |
Output is correct |
41 |
Correct |
288 ms |
25808 KB |
Output is correct |
42 |
Correct |
300 ms |
25936 KB |
Output is correct |
43 |
Correct |
443 ms |
62032 KB |
Output is correct |
44 |
Correct |
451 ms |
62096 KB |
Output is correct |
45 |
Correct |
420 ms |
62112 KB |
Output is correct |
46 |
Correct |
438 ms |
62036 KB |
Output is correct |
47 |
Correct |
458 ms |
62036 KB |
Output is correct |
48 |
Correct |
393 ms |
62028 KB |
Output is correct |
49 |
Correct |
420 ms |
62036 KB |
Output is correct |
50 |
Correct |
430 ms |
62136 KB |
Output is correct |
51 |
Correct |
449 ms |
62056 KB |
Output is correct |
52 |
Correct |
438 ms |
62036 KB |
Output is correct |
53 |
Correct |
440 ms |
62032 KB |
Output is correct |
54 |
Correct |
426 ms |
62036 KB |
Output is correct |
55 |
Correct |
444 ms |
62080 KB |
Output is correct |
56 |
Correct |
428 ms |
62116 KB |
Output is correct |
57 |
Correct |
439 ms |
61976 KB |
Output is correct |
58 |
Correct |
445 ms |
61996 KB |
Output is correct |
59 |
Correct |
430 ms |
62036 KB |
Output is correct |
60 |
Correct |
432 ms |
62064 KB |
Output is correct |
61 |
Correct |
434 ms |
61924 KB |
Output is correct |
62 |
Correct |
427 ms |
62036 KB |
Output is correct |
63 |
Correct |
421 ms |
62036 KB |
Output is correct |
64 |
Execution timed out |
1129 ms |
127764 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |