#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("popcnt")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=2e5+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
const ldb eps=1e-6;
const ldb PI=acos(-1.0);
const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
// const string ct="abcdef";
// const string ct="abcdefghijklmnop";
// const string ct="abcdefghijklmnopABCDEFGHIJKLMNOP";
const string ct="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
const int cs = ct.size();
template<typename T>
using vvector = vector<vector<T>>;
ll cnt[128][128];
ll cnt3[70][70][70];
ll solve(vector<string> &ss) {
sort(all(ss));
ss.resize(unique(all(ss))-ss.begin());
memset(cnt,0,sizeof(cnt));
for (auto s:ss) {
cnt[s[0]][s.back()]++;
}
memset(cnt3,0,sizeof(cnt3));
for (int i=0;i<cs;i++) {
for (int j=i;j<cs;j++) {
for (int k=j;k<cs;k++) {
ll ans=0;
for (int l=0;l<cs;l++) {
ans+=cnt[ct[i]][ct[l]]*cnt[ct[j]][ct[l]]%P*cnt[ct[k]][ct[l]]%P;
ans%=P;
}
cnt3[i][j][k]=ans;
}
}
}
auto srt = [&](int a,int b,int c,int d) {
array<int,4> ans={a,b,c,d};
sort(all(ans));
return ans;
};
ll ans=0;
for (int i=0;i<cs;i++) {
for (int j=i;j<cs;j++) {
for (int k=j;k<cs;k++) {
for (int l=k;l<cs;l++) {
ll now=1;
if (i==j and j==k and k==l) now=1;
else if ((i==j and j==k) or (j==k and k==l)) now=4;
else if (i==j and k==l) now=6;
else if (i==j or j==k or k==l) now=12;
else now=24;
now*=cnt3[i][j][k];
now%=P;
now*=cnt3[i][j][l];
now%=P;
now*=cnt3[i][k][l];
now%=P;
now*=cnt3[j][k][l];
now%=P;
ans+=now;
ans%=P;
}
}
}
}
return ans;
}
int main() {
speed;
int n;
vector<string> l[11];
cin>>n;
for (int i=0;i<n;i++) {
string s;
cin>>s;
l[s.size()].push_back(s);
reverse(all(s));
l[s.size()].push_back(s);
}
ll ans=0;
for (int k=3;k<=10;k++) {
// cout<<k<<" k\n"<<flush;
ans+=solve(l[k]);
ans%=P;
}
cout<<ans<<"\n";
return 0;
}
Compilation message
cubeword.cpp: In function 'll solve(std::vector<std::__cxx11::basic_string<char> >&)':
cubeword.cpp:38:17: warning: array subscript has type 'char' [-Wchar-subscripts]
38 | cnt[s[0]][s.back()]++;
| ^
cubeword.cpp:38:25: warning: array subscript has type 'char' [-Wchar-subscripts]
38 | cnt[s[0]][s.back()]++;
| ~~~~~~^~
cubeword.cpp:46:35: warning: array subscript has type 'char' [-Wchar-subscripts]
46 | ans+=cnt[ct[i]][ct[l]]*cnt[ct[j]][ct[l]]%P*cnt[ct[k]][ct[l]]%P;
| ^
cubeword.cpp:46:42: warning: array subscript has type 'char' [-Wchar-subscripts]
46 | ans+=cnt[ct[i]][ct[l]]*cnt[ct[j]][ct[l]]%P*cnt[ct[k]][ct[l]]%P;
| ^
cubeword.cpp:46:53: warning: array subscript has type 'char' [-Wchar-subscripts]
46 | ans+=cnt[ct[i]][ct[l]]*cnt[ct[j]][ct[l]]%P*cnt[ct[k]][ct[l]]%P;
| ^
cubeword.cpp:46:60: warning: array subscript has type 'char' [-Wchar-subscripts]
46 | ans+=cnt[ct[i]][ct[l]]*cnt[ct[j]][ct[l]]%P*cnt[ct[k]][ct[l]]%P;
| ^
cubeword.cpp:46:73: warning: array subscript has type 'char' [-Wchar-subscripts]
46 | ans+=cnt[ct[i]][ct[l]]*cnt[ct[j]][ct[l]]%P*cnt[ct[k]][ct[l]]%P;
| ^
cubeword.cpp:46:80: warning: array subscript has type 'char' [-Wchar-subscripts]
46 | ans+=cnt[ct[i]][ct[l]]*cnt[ct[j]][ct[l]]%P*cnt[ct[k]][ct[l]]%P;
| ^
cubeword.cpp:53:10: warning: variable 'srt' set but not used [-Wunused-but-set-variable]
53 | auto srt = [&](int a,int b,int c,int d) {
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
14052 KB |
Output is correct |
2 |
Correct |
211 ms |
14244 KB |
Output is correct |
3 |
Correct |
199 ms |
13076 KB |
Output is correct |
4 |
Correct |
207 ms |
13548 KB |
Output is correct |
5 |
Correct |
201 ms |
14148 KB |
Output is correct |
6 |
Correct |
201 ms |
14352 KB |
Output is correct |
7 |
Correct |
200 ms |
14072 KB |
Output is correct |
8 |
Correct |
209 ms |
13928 KB |
Output is correct |
9 |
Correct |
211 ms |
14032 KB |
Output is correct |
10 |
Correct |
201 ms |
14108 KB |
Output is correct |
11 |
Correct |
203 ms |
14208 KB |
Output is correct |
12 |
Correct |
207 ms |
14256 KB |
Output is correct |
13 |
Correct |
200 ms |
13360 KB |
Output is correct |
14 |
Correct |
201 ms |
13920 KB |
Output is correct |
15 |
Correct |
216 ms |
14072 KB |
Output is correct |
16 |
Correct |
209 ms |
14204 KB |
Output is correct |
17 |
Correct |
203 ms |
13292 KB |
Output is correct |
18 |
Correct |
201 ms |
13968 KB |
Output is correct |
19 |
Correct |
212 ms |
14044 KB |
Output is correct |
20 |
Correct |
215 ms |
14064 KB |
Output is correct |
21 |
Correct |
198 ms |
13380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
14052 KB |
Output is correct |
2 |
Correct |
211 ms |
14244 KB |
Output is correct |
3 |
Correct |
199 ms |
13076 KB |
Output is correct |
4 |
Correct |
207 ms |
13548 KB |
Output is correct |
5 |
Correct |
201 ms |
14148 KB |
Output is correct |
6 |
Correct |
201 ms |
14352 KB |
Output is correct |
7 |
Correct |
200 ms |
14072 KB |
Output is correct |
8 |
Correct |
209 ms |
13928 KB |
Output is correct |
9 |
Correct |
211 ms |
14032 KB |
Output is correct |
10 |
Correct |
201 ms |
14108 KB |
Output is correct |
11 |
Correct |
203 ms |
14208 KB |
Output is correct |
12 |
Correct |
207 ms |
14256 KB |
Output is correct |
13 |
Correct |
200 ms |
13360 KB |
Output is correct |
14 |
Correct |
201 ms |
13920 KB |
Output is correct |
15 |
Correct |
216 ms |
14072 KB |
Output is correct |
16 |
Correct |
209 ms |
14204 KB |
Output is correct |
17 |
Correct |
203 ms |
13292 KB |
Output is correct |
18 |
Correct |
201 ms |
13968 KB |
Output is correct |
19 |
Correct |
212 ms |
14044 KB |
Output is correct |
20 |
Correct |
215 ms |
14064 KB |
Output is correct |
21 |
Correct |
198 ms |
13380 KB |
Output is correct |
22 |
Correct |
206 ms |
10452 KB |
Output is correct |
23 |
Correct |
197 ms |
9560 KB |
Output is correct |
24 |
Correct |
199 ms |
10632 KB |
Output is correct |
25 |
Correct |
199 ms |
10500 KB |
Output is correct |
26 |
Correct |
199 ms |
9652 KB |
Output is correct |
27 |
Correct |
209 ms |
10524 KB |
Output is correct |
28 |
Correct |
210 ms |
10472 KB |
Output is correct |
29 |
Correct |
208 ms |
10468 KB |
Output is correct |
30 |
Correct |
200 ms |
10260 KB |
Output is correct |
31 |
Correct |
203 ms |
10328 KB |
Output is correct |
32 |
Correct |
201 ms |
10228 KB |
Output is correct |
33 |
Correct |
199 ms |
10420 KB |
Output is correct |
34 |
Correct |
198 ms |
10456 KB |
Output is correct |
35 |
Correct |
212 ms |
10520 KB |
Output is correct |
36 |
Correct |
204 ms |
10376 KB |
Output is correct |
37 |
Correct |
201 ms |
10336 KB |
Output is correct |
38 |
Correct |
207 ms |
9724 KB |
Output is correct |
39 |
Correct |
204 ms |
10588 KB |
Output is correct |
40 |
Correct |
199 ms |
10340 KB |
Output is correct |
41 |
Correct |
199 ms |
10636 KB |
Output is correct |
42 |
Correct |
202 ms |
10448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
14052 KB |
Output is correct |
2 |
Correct |
211 ms |
14244 KB |
Output is correct |
3 |
Correct |
199 ms |
13076 KB |
Output is correct |
4 |
Correct |
207 ms |
13548 KB |
Output is correct |
5 |
Correct |
201 ms |
14148 KB |
Output is correct |
6 |
Correct |
201 ms |
14352 KB |
Output is correct |
7 |
Correct |
200 ms |
14072 KB |
Output is correct |
8 |
Correct |
209 ms |
13928 KB |
Output is correct |
9 |
Correct |
211 ms |
14032 KB |
Output is correct |
10 |
Correct |
201 ms |
14108 KB |
Output is correct |
11 |
Correct |
203 ms |
14208 KB |
Output is correct |
12 |
Correct |
207 ms |
14256 KB |
Output is correct |
13 |
Correct |
200 ms |
13360 KB |
Output is correct |
14 |
Correct |
201 ms |
13920 KB |
Output is correct |
15 |
Correct |
216 ms |
14072 KB |
Output is correct |
16 |
Correct |
209 ms |
14204 KB |
Output is correct |
17 |
Correct |
203 ms |
13292 KB |
Output is correct |
18 |
Correct |
201 ms |
13968 KB |
Output is correct |
19 |
Correct |
212 ms |
14044 KB |
Output is correct |
20 |
Correct |
215 ms |
14064 KB |
Output is correct |
21 |
Correct |
198 ms |
13380 KB |
Output is correct |
22 |
Correct |
206 ms |
10452 KB |
Output is correct |
23 |
Correct |
197 ms |
9560 KB |
Output is correct |
24 |
Correct |
199 ms |
10632 KB |
Output is correct |
25 |
Correct |
199 ms |
10500 KB |
Output is correct |
26 |
Correct |
199 ms |
9652 KB |
Output is correct |
27 |
Correct |
209 ms |
10524 KB |
Output is correct |
28 |
Correct |
210 ms |
10472 KB |
Output is correct |
29 |
Correct |
208 ms |
10468 KB |
Output is correct |
30 |
Correct |
200 ms |
10260 KB |
Output is correct |
31 |
Correct |
203 ms |
10328 KB |
Output is correct |
32 |
Correct |
201 ms |
10228 KB |
Output is correct |
33 |
Correct |
199 ms |
10420 KB |
Output is correct |
34 |
Correct |
198 ms |
10456 KB |
Output is correct |
35 |
Correct |
212 ms |
10520 KB |
Output is correct |
36 |
Correct |
204 ms |
10376 KB |
Output is correct |
37 |
Correct |
201 ms |
10336 KB |
Output is correct |
38 |
Correct |
207 ms |
9724 KB |
Output is correct |
39 |
Correct |
204 ms |
10588 KB |
Output is correct |
40 |
Correct |
199 ms |
10340 KB |
Output is correct |
41 |
Correct |
199 ms |
10636 KB |
Output is correct |
42 |
Correct |
202 ms |
10448 KB |
Output is correct |
43 |
Correct |
206 ms |
10424 KB |
Output is correct |
44 |
Correct |
200 ms |
9484 KB |
Output is correct |
45 |
Correct |
201 ms |
10416 KB |
Output is correct |
46 |
Correct |
206 ms |
10252 KB |
Output is correct |
47 |
Correct |
206 ms |
10324 KB |
Output is correct |
48 |
Correct |
209 ms |
10656 KB |
Output is correct |
49 |
Correct |
205 ms |
10820 KB |
Output is correct |
50 |
Correct |
197 ms |
10608 KB |
Output is correct |
51 |
Correct |
201 ms |
10520 KB |
Output is correct |
52 |
Correct |
197 ms |
10248 KB |
Output is correct |
53 |
Correct |
211 ms |
10372 KB |
Output is correct |
54 |
Correct |
197 ms |
9864 KB |
Output is correct |
55 |
Correct |
201 ms |
9996 KB |
Output is correct |
56 |
Correct |
204 ms |
9464 KB |
Output is correct |
57 |
Correct |
203 ms |
10628 KB |
Output is correct |
58 |
Correct |
200 ms |
10056 KB |
Output is correct |
59 |
Correct |
203 ms |
10688 KB |
Output is correct |
60 |
Correct |
211 ms |
10032 KB |
Output is correct |
61 |
Correct |
205 ms |
9560 KB |
Output is correct |
62 |
Correct |
200 ms |
10464 KB |
Output is correct |
63 |
Correct |
204 ms |
10668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
14052 KB |
Output is correct |
2 |
Correct |
211 ms |
14244 KB |
Output is correct |
3 |
Correct |
199 ms |
13076 KB |
Output is correct |
4 |
Correct |
207 ms |
13548 KB |
Output is correct |
5 |
Correct |
201 ms |
14148 KB |
Output is correct |
6 |
Correct |
201 ms |
14352 KB |
Output is correct |
7 |
Correct |
200 ms |
14072 KB |
Output is correct |
8 |
Correct |
209 ms |
13928 KB |
Output is correct |
9 |
Correct |
211 ms |
14032 KB |
Output is correct |
10 |
Correct |
201 ms |
14108 KB |
Output is correct |
11 |
Correct |
203 ms |
14208 KB |
Output is correct |
12 |
Correct |
207 ms |
14256 KB |
Output is correct |
13 |
Correct |
200 ms |
13360 KB |
Output is correct |
14 |
Correct |
201 ms |
13920 KB |
Output is correct |
15 |
Correct |
216 ms |
14072 KB |
Output is correct |
16 |
Correct |
209 ms |
14204 KB |
Output is correct |
17 |
Correct |
203 ms |
13292 KB |
Output is correct |
18 |
Correct |
201 ms |
13968 KB |
Output is correct |
19 |
Correct |
212 ms |
14044 KB |
Output is correct |
20 |
Correct |
215 ms |
14064 KB |
Output is correct |
21 |
Correct |
198 ms |
13380 KB |
Output is correct |
22 |
Correct |
206 ms |
10452 KB |
Output is correct |
23 |
Correct |
197 ms |
9560 KB |
Output is correct |
24 |
Correct |
199 ms |
10632 KB |
Output is correct |
25 |
Correct |
199 ms |
10500 KB |
Output is correct |
26 |
Correct |
199 ms |
9652 KB |
Output is correct |
27 |
Correct |
209 ms |
10524 KB |
Output is correct |
28 |
Correct |
210 ms |
10472 KB |
Output is correct |
29 |
Correct |
208 ms |
10468 KB |
Output is correct |
30 |
Correct |
200 ms |
10260 KB |
Output is correct |
31 |
Correct |
203 ms |
10328 KB |
Output is correct |
32 |
Correct |
201 ms |
10228 KB |
Output is correct |
33 |
Correct |
199 ms |
10420 KB |
Output is correct |
34 |
Correct |
198 ms |
10456 KB |
Output is correct |
35 |
Correct |
212 ms |
10520 KB |
Output is correct |
36 |
Correct |
204 ms |
10376 KB |
Output is correct |
37 |
Correct |
201 ms |
10336 KB |
Output is correct |
38 |
Correct |
207 ms |
9724 KB |
Output is correct |
39 |
Correct |
204 ms |
10588 KB |
Output is correct |
40 |
Correct |
199 ms |
10340 KB |
Output is correct |
41 |
Correct |
199 ms |
10636 KB |
Output is correct |
42 |
Correct |
202 ms |
10448 KB |
Output is correct |
43 |
Correct |
206 ms |
10424 KB |
Output is correct |
44 |
Correct |
200 ms |
9484 KB |
Output is correct |
45 |
Correct |
201 ms |
10416 KB |
Output is correct |
46 |
Correct |
206 ms |
10252 KB |
Output is correct |
47 |
Correct |
206 ms |
10324 KB |
Output is correct |
48 |
Correct |
209 ms |
10656 KB |
Output is correct |
49 |
Correct |
205 ms |
10820 KB |
Output is correct |
50 |
Correct |
197 ms |
10608 KB |
Output is correct |
51 |
Correct |
201 ms |
10520 KB |
Output is correct |
52 |
Correct |
197 ms |
10248 KB |
Output is correct |
53 |
Correct |
211 ms |
10372 KB |
Output is correct |
54 |
Correct |
197 ms |
9864 KB |
Output is correct |
55 |
Correct |
201 ms |
9996 KB |
Output is correct |
56 |
Correct |
204 ms |
9464 KB |
Output is correct |
57 |
Correct |
203 ms |
10628 KB |
Output is correct |
58 |
Correct |
200 ms |
10056 KB |
Output is correct |
59 |
Correct |
203 ms |
10688 KB |
Output is correct |
60 |
Correct |
211 ms |
10032 KB |
Output is correct |
61 |
Correct |
205 ms |
9560 KB |
Output is correct |
62 |
Correct |
200 ms |
10464 KB |
Output is correct |
63 |
Correct |
204 ms |
10668 KB |
Output is correct |
64 |
Correct |
205 ms |
10660 KB |
Output is correct |
65 |
Correct |
203 ms |
10684 KB |
Output is correct |
66 |
Correct |
205 ms |
10196 KB |
Output is correct |
67 |
Correct |
208 ms |
10240 KB |
Output is correct |
68 |
Correct |
200 ms |
10600 KB |
Output is correct |
69 |
Correct |
208 ms |
10660 KB |
Output is correct |
70 |
Correct |
199 ms |
10568 KB |
Output is correct |
71 |
Correct |
200 ms |
10316 KB |
Output is correct |
72 |
Correct |
219 ms |
10660 KB |
Output is correct |
73 |
Correct |
204 ms |
10444 KB |
Output is correct |
74 |
Correct |
215 ms |
10740 KB |
Output is correct |
75 |
Correct |
200 ms |
10520 KB |
Output is correct |
76 |
Correct |
207 ms |
10468 KB |
Output is correct |
77 |
Correct |
205 ms |
10384 KB |
Output is correct |
78 |
Correct |
201 ms |
10428 KB |
Output is correct |
79 |
Correct |
209 ms |
10428 KB |
Output is correct |
80 |
Correct |
206 ms |
10524 KB |
Output is correct |
81 |
Correct |
216 ms |
10700 KB |
Output is correct |
82 |
Correct |
200 ms |
10512 KB |
Output is correct |
83 |
Correct |
197 ms |
10536 KB |
Output is correct |
84 |
Correct |
197 ms |
10816 KB |
Output is correct |