#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=0;j<cs;j++) {
for (int k=0;k<cs;k++) {
for (int l=0;l<cs;l++) {
ll now=1;
auto [ni,nj,nk,nl] = srt(i,j,k,l);
now*=cnt3[ni][nj][nk];
now%=P;
now*=cnt3[ni][nj][nl];
now%=P;
now*=cnt3[ni][nk][nl];
now%=P;
now*=cnt3[nj][nk][nl];
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;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
269 ms |
13284 KB |
Output is correct |
2 |
Correct |
275 ms |
14004 KB |
Output is correct |
3 |
Correct |
267 ms |
14100 KB |
Output is correct |
4 |
Correct |
268 ms |
14080 KB |
Output is correct |
5 |
Correct |
282 ms |
14148 KB |
Output is correct |
6 |
Correct |
270 ms |
14352 KB |
Output is correct |
7 |
Correct |
274 ms |
14072 KB |
Output is correct |
8 |
Correct |
273 ms |
13992 KB |
Output is correct |
9 |
Correct |
274 ms |
14036 KB |
Output is correct |
10 |
Correct |
268 ms |
14396 KB |
Output is correct |
11 |
Correct |
278 ms |
14220 KB |
Output is correct |
12 |
Correct |
270 ms |
14252 KB |
Output is correct |
13 |
Correct |
279 ms |
14248 KB |
Output is correct |
14 |
Correct |
269 ms |
14124 KB |
Output is correct |
15 |
Correct |
276 ms |
14064 KB |
Output is correct |
16 |
Correct |
278 ms |
14204 KB |
Output is correct |
17 |
Correct |
283 ms |
14060 KB |
Output is correct |
18 |
Correct |
273 ms |
13968 KB |
Output is correct |
19 |
Correct |
273 ms |
14044 KB |
Output is correct |
20 |
Correct |
269 ms |
14052 KB |
Output is correct |
21 |
Correct |
274 ms |
14148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
269 ms |
13284 KB |
Output is correct |
2 |
Correct |
275 ms |
14004 KB |
Output is correct |
3 |
Correct |
267 ms |
14100 KB |
Output is correct |
4 |
Correct |
268 ms |
14080 KB |
Output is correct |
5 |
Correct |
282 ms |
14148 KB |
Output is correct |
6 |
Correct |
270 ms |
14352 KB |
Output is correct |
7 |
Correct |
274 ms |
14072 KB |
Output is correct |
8 |
Correct |
273 ms |
13992 KB |
Output is correct |
9 |
Correct |
274 ms |
14036 KB |
Output is correct |
10 |
Correct |
268 ms |
14396 KB |
Output is correct |
11 |
Correct |
278 ms |
14220 KB |
Output is correct |
12 |
Correct |
270 ms |
14252 KB |
Output is correct |
13 |
Correct |
279 ms |
14248 KB |
Output is correct |
14 |
Correct |
269 ms |
14124 KB |
Output is correct |
15 |
Correct |
276 ms |
14064 KB |
Output is correct |
16 |
Correct |
278 ms |
14204 KB |
Output is correct |
17 |
Correct |
283 ms |
14060 KB |
Output is correct |
18 |
Correct |
273 ms |
13968 KB |
Output is correct |
19 |
Correct |
273 ms |
14044 KB |
Output is correct |
20 |
Correct |
269 ms |
14052 KB |
Output is correct |
21 |
Correct |
274 ms |
14148 KB |
Output is correct |
22 |
Correct |
273 ms |
10452 KB |
Output is correct |
23 |
Correct |
271 ms |
10464 KB |
Output is correct |
24 |
Correct |
275 ms |
10624 KB |
Output is correct |
25 |
Correct |
273 ms |
10532 KB |
Output is correct |
26 |
Correct |
275 ms |
10588 KB |
Output is correct |
27 |
Correct |
284 ms |
10688 KB |
Output is correct |
28 |
Correct |
268 ms |
10336 KB |
Output is correct |
29 |
Correct |
279 ms |
10416 KB |
Output is correct |
30 |
Correct |
266 ms |
10260 KB |
Output is correct |
31 |
Correct |
270 ms |
10336 KB |
Output is correct |
32 |
Correct |
279 ms |
10320 KB |
Output is correct |
33 |
Correct |
272 ms |
10428 KB |
Output is correct |
34 |
Correct |
270 ms |
10392 KB |
Output is correct |
35 |
Correct |
273 ms |
10520 KB |
Output is correct |
36 |
Correct |
266 ms |
10556 KB |
Output is correct |
37 |
Correct |
274 ms |
10308 KB |
Output is correct |
38 |
Correct |
286 ms |
10748 KB |
Output is correct |
39 |
Correct |
276 ms |
10408 KB |
Output is correct |
40 |
Correct |
279 ms |
10332 KB |
Output is correct |
41 |
Correct |
276 ms |
10628 KB |
Output is correct |
42 |
Correct |
280 ms |
10456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
269 ms |
13284 KB |
Output is correct |
2 |
Correct |
275 ms |
14004 KB |
Output is correct |
3 |
Correct |
267 ms |
14100 KB |
Output is correct |
4 |
Correct |
268 ms |
14080 KB |
Output is correct |
5 |
Correct |
282 ms |
14148 KB |
Output is correct |
6 |
Correct |
270 ms |
14352 KB |
Output is correct |
7 |
Correct |
274 ms |
14072 KB |
Output is correct |
8 |
Correct |
273 ms |
13992 KB |
Output is correct |
9 |
Correct |
274 ms |
14036 KB |
Output is correct |
10 |
Correct |
268 ms |
14396 KB |
Output is correct |
11 |
Correct |
278 ms |
14220 KB |
Output is correct |
12 |
Correct |
270 ms |
14252 KB |
Output is correct |
13 |
Correct |
279 ms |
14248 KB |
Output is correct |
14 |
Correct |
269 ms |
14124 KB |
Output is correct |
15 |
Correct |
276 ms |
14064 KB |
Output is correct |
16 |
Correct |
278 ms |
14204 KB |
Output is correct |
17 |
Correct |
283 ms |
14060 KB |
Output is correct |
18 |
Correct |
273 ms |
13968 KB |
Output is correct |
19 |
Correct |
273 ms |
14044 KB |
Output is correct |
20 |
Correct |
269 ms |
14052 KB |
Output is correct |
21 |
Correct |
274 ms |
14148 KB |
Output is correct |
22 |
Correct |
273 ms |
10452 KB |
Output is correct |
23 |
Correct |
271 ms |
10464 KB |
Output is correct |
24 |
Correct |
275 ms |
10624 KB |
Output is correct |
25 |
Correct |
273 ms |
10532 KB |
Output is correct |
26 |
Correct |
275 ms |
10588 KB |
Output is correct |
27 |
Correct |
284 ms |
10688 KB |
Output is correct |
28 |
Correct |
268 ms |
10336 KB |
Output is correct |
29 |
Correct |
279 ms |
10416 KB |
Output is correct |
30 |
Correct |
266 ms |
10260 KB |
Output is correct |
31 |
Correct |
270 ms |
10336 KB |
Output is correct |
32 |
Correct |
279 ms |
10320 KB |
Output is correct |
33 |
Correct |
272 ms |
10428 KB |
Output is correct |
34 |
Correct |
270 ms |
10392 KB |
Output is correct |
35 |
Correct |
273 ms |
10520 KB |
Output is correct |
36 |
Correct |
266 ms |
10556 KB |
Output is correct |
37 |
Correct |
274 ms |
10308 KB |
Output is correct |
38 |
Correct |
286 ms |
10748 KB |
Output is correct |
39 |
Correct |
276 ms |
10408 KB |
Output is correct |
40 |
Correct |
279 ms |
10332 KB |
Output is correct |
41 |
Correct |
276 ms |
10628 KB |
Output is correct |
42 |
Correct |
280 ms |
10456 KB |
Output is correct |
43 |
Correct |
273 ms |
10416 KB |
Output is correct |
44 |
Correct |
267 ms |
10460 KB |
Output is correct |
45 |
Correct |
268 ms |
10416 KB |
Output is correct |
46 |
Correct |
275 ms |
10264 KB |
Output is correct |
47 |
Correct |
270 ms |
10304 KB |
Output is correct |
48 |
Correct |
269 ms |
10644 KB |
Output is correct |
49 |
Correct |
278 ms |
10796 KB |
Output is correct |
50 |
Correct |
287 ms |
10656 KB |
Output is correct |
51 |
Correct |
274 ms |
10660 KB |
Output is correct |
52 |
Correct |
272 ms |
10248 KB |
Output is correct |
53 |
Correct |
292 ms |
10364 KB |
Output is correct |
54 |
Correct |
277 ms |
10624 KB |
Output is correct |
55 |
Correct |
272 ms |
10764 KB |
Output is correct |
56 |
Correct |
277 ms |
10436 KB |
Output is correct |
57 |
Correct |
274 ms |
10632 KB |
Output is correct |
58 |
Correct |
280 ms |
10824 KB |
Output is correct |
59 |
Correct |
283 ms |
10688 KB |
Output is correct |
60 |
Correct |
272 ms |
10800 KB |
Output is correct |
61 |
Correct |
276 ms |
10328 KB |
Output is correct |
62 |
Correct |
271 ms |
10512 KB |
Output is correct |
63 |
Correct |
268 ms |
10668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
269 ms |
13284 KB |
Output is correct |
2 |
Correct |
275 ms |
14004 KB |
Output is correct |
3 |
Correct |
267 ms |
14100 KB |
Output is correct |
4 |
Correct |
268 ms |
14080 KB |
Output is correct |
5 |
Correct |
282 ms |
14148 KB |
Output is correct |
6 |
Correct |
270 ms |
14352 KB |
Output is correct |
7 |
Correct |
274 ms |
14072 KB |
Output is correct |
8 |
Correct |
273 ms |
13992 KB |
Output is correct |
9 |
Correct |
274 ms |
14036 KB |
Output is correct |
10 |
Correct |
268 ms |
14396 KB |
Output is correct |
11 |
Correct |
278 ms |
14220 KB |
Output is correct |
12 |
Correct |
270 ms |
14252 KB |
Output is correct |
13 |
Correct |
279 ms |
14248 KB |
Output is correct |
14 |
Correct |
269 ms |
14124 KB |
Output is correct |
15 |
Correct |
276 ms |
14064 KB |
Output is correct |
16 |
Correct |
278 ms |
14204 KB |
Output is correct |
17 |
Correct |
283 ms |
14060 KB |
Output is correct |
18 |
Correct |
273 ms |
13968 KB |
Output is correct |
19 |
Correct |
273 ms |
14044 KB |
Output is correct |
20 |
Correct |
269 ms |
14052 KB |
Output is correct |
21 |
Correct |
274 ms |
14148 KB |
Output is correct |
22 |
Correct |
273 ms |
10452 KB |
Output is correct |
23 |
Correct |
271 ms |
10464 KB |
Output is correct |
24 |
Correct |
275 ms |
10624 KB |
Output is correct |
25 |
Correct |
273 ms |
10532 KB |
Output is correct |
26 |
Correct |
275 ms |
10588 KB |
Output is correct |
27 |
Correct |
284 ms |
10688 KB |
Output is correct |
28 |
Correct |
268 ms |
10336 KB |
Output is correct |
29 |
Correct |
279 ms |
10416 KB |
Output is correct |
30 |
Correct |
266 ms |
10260 KB |
Output is correct |
31 |
Correct |
270 ms |
10336 KB |
Output is correct |
32 |
Correct |
279 ms |
10320 KB |
Output is correct |
33 |
Correct |
272 ms |
10428 KB |
Output is correct |
34 |
Correct |
270 ms |
10392 KB |
Output is correct |
35 |
Correct |
273 ms |
10520 KB |
Output is correct |
36 |
Correct |
266 ms |
10556 KB |
Output is correct |
37 |
Correct |
274 ms |
10308 KB |
Output is correct |
38 |
Correct |
286 ms |
10748 KB |
Output is correct |
39 |
Correct |
276 ms |
10408 KB |
Output is correct |
40 |
Correct |
279 ms |
10332 KB |
Output is correct |
41 |
Correct |
276 ms |
10628 KB |
Output is correct |
42 |
Correct |
280 ms |
10456 KB |
Output is correct |
43 |
Correct |
273 ms |
10416 KB |
Output is correct |
44 |
Correct |
267 ms |
10460 KB |
Output is correct |
45 |
Correct |
268 ms |
10416 KB |
Output is correct |
46 |
Correct |
275 ms |
10264 KB |
Output is correct |
47 |
Correct |
270 ms |
10304 KB |
Output is correct |
48 |
Correct |
269 ms |
10644 KB |
Output is correct |
49 |
Correct |
278 ms |
10796 KB |
Output is correct |
50 |
Correct |
287 ms |
10656 KB |
Output is correct |
51 |
Correct |
274 ms |
10660 KB |
Output is correct |
52 |
Correct |
272 ms |
10248 KB |
Output is correct |
53 |
Correct |
292 ms |
10364 KB |
Output is correct |
54 |
Correct |
277 ms |
10624 KB |
Output is correct |
55 |
Correct |
272 ms |
10764 KB |
Output is correct |
56 |
Correct |
277 ms |
10436 KB |
Output is correct |
57 |
Correct |
274 ms |
10632 KB |
Output is correct |
58 |
Correct |
280 ms |
10824 KB |
Output is correct |
59 |
Correct |
283 ms |
10688 KB |
Output is correct |
60 |
Correct |
272 ms |
10800 KB |
Output is correct |
61 |
Correct |
276 ms |
10328 KB |
Output is correct |
62 |
Correct |
271 ms |
10512 KB |
Output is correct |
63 |
Correct |
268 ms |
10668 KB |
Output is correct |
64 |
Incorrect |
266 ms |
10668 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |