#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target("popcnt")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using lld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int,int>;
using pll = pair<ll, ll>;
using vii = vector<ii>;
using vpll = vector<pll>;
#define endl '\n'
#define all(x) x.begin(),x.end()
#define lsb(x) x&(-x)
#define gcd(a,b) __gcd(a,b)
#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fls cout.flush()
#define fore(i,l,r) for(auto i=l;i<r;i++)
#define fo(i,n) fore(i,0,n)
#define forex(i,r,l) for(auto i=r; i>=l;i--)
#define ffo(i,n) forex(i,n-1,0)
bool cmin(int &a, int b){if(b<a){a=b;return 1;}return 0;}
bool cmax(int &a, int b){if(b>a){a=b;return 1;}return 0;}
void valid(ll in){cout<<((in)?"YES\n":"NO\n");}
ll lcm(ll a, ll b){return (a/gcd(a,b))*b;}
ll gauss(ll n){return (n*(n+1))/2;}
const int N = 1e5 + 7, LOG=20,mod=998244353;
int n,X=0;
ll cnt[11][64][64][64], cnt2[11][64][64];
string s[N];
map<char, int> let;
void test_case(){
cin>>n;
set<string> st;
fo(i,n){
cin>>s[i];
int t=sz(s[i]);
st.insert(s[i]);
reverse(all(s[i]));
st.insert(s[i]);
}
for(auto e:st)cnt2[sz(e)][let[e[0]]][let[e.back()]]++;
fo(a,X){
fo(b,X){
fo(c,X){
fo(d,X){
fore(t, 3, 11){
ll aa=1;
aa=aa*cnt2[t][d][a];
aa=aa*cnt2[t][b][d];
aa=aa*cnt2[t][d][c];
cnt[t][a][b][c]=(cnt[t][a][b][c]+aa)%mod;
}
}
}
}
}
ll ans=0;
fo(a,X){
fo(b,X){
fo(c,X){
fo(d,X){
fore(t, 3, 11){
ll aa=1;
aa=(aa*cnt[t][a][b][c])%mod;
aa=(aa*cnt[t][d][a][b])%mod;
aa=(aa*cnt[t][d][c][b])%mod;
aa=(aa*cnt[t][a][d][c])%mod;
ans=(ans+aa)%mod;
}
}
}
}
}
cout<<ans<<endl;
}
int main(){cin.tie(0)->sync_with_stdio(0);
for(char a='a';a<='p';a++)let[a]=X++;
for(char a='A';a<='P';a++)let[a]=X++;
for(char a='1';a<='9';a++)let[a]=X++;
int t=1;
// cin >> t;
while(t--)test_case();
}
Compilation message
cubeword.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
4 | #pragma GCC optimization ("O3")
|
cubeword.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
5 | #pragma GCC optimization ("unroll-loops")
|
cubeword.cpp: In function 'void test_case()':
cubeword.cpp:50:13: warning: unused variable 't' [-Wunused-variable]
50 | int t=sz(s[i]);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
378 ms |
26964 KB |
Output is correct |
2 |
Correct |
372 ms |
27036 KB |
Output is correct |
3 |
Correct |
371 ms |
26964 KB |
Output is correct |
4 |
Correct |
354 ms |
26956 KB |
Output is correct |
5 |
Correct |
363 ms |
26960 KB |
Output is correct |
6 |
Correct |
370 ms |
26960 KB |
Output is correct |
7 |
Correct |
374 ms |
27224 KB |
Output is correct |
8 |
Correct |
393 ms |
26964 KB |
Output is correct |
9 |
Correct |
377 ms |
26964 KB |
Output is correct |
10 |
Correct |
346 ms |
26912 KB |
Output is correct |
11 |
Correct |
367 ms |
26876 KB |
Output is correct |
12 |
Correct |
397 ms |
26908 KB |
Output is correct |
13 |
Correct |
365 ms |
26964 KB |
Output is correct |
14 |
Correct |
351 ms |
26960 KB |
Output is correct |
15 |
Correct |
381 ms |
26960 KB |
Output is correct |
16 |
Correct |
394 ms |
26960 KB |
Output is correct |
17 |
Correct |
373 ms |
26964 KB |
Output is correct |
18 |
Correct |
369 ms |
27032 KB |
Output is correct |
19 |
Correct |
379 ms |
27220 KB |
Output is correct |
20 |
Correct |
411 ms |
26964 KB |
Output is correct |
21 |
Correct |
362 ms |
26852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
378 ms |
26964 KB |
Output is correct |
2 |
Correct |
372 ms |
27036 KB |
Output is correct |
3 |
Correct |
371 ms |
26964 KB |
Output is correct |
4 |
Correct |
354 ms |
26956 KB |
Output is correct |
5 |
Correct |
363 ms |
26960 KB |
Output is correct |
6 |
Correct |
370 ms |
26960 KB |
Output is correct |
7 |
Correct |
374 ms |
27224 KB |
Output is correct |
8 |
Correct |
393 ms |
26964 KB |
Output is correct |
9 |
Correct |
377 ms |
26964 KB |
Output is correct |
10 |
Correct |
346 ms |
26912 KB |
Output is correct |
11 |
Correct |
367 ms |
26876 KB |
Output is correct |
12 |
Correct |
397 ms |
26908 KB |
Output is correct |
13 |
Correct |
365 ms |
26964 KB |
Output is correct |
14 |
Correct |
351 ms |
26960 KB |
Output is correct |
15 |
Correct |
381 ms |
26960 KB |
Output is correct |
16 |
Correct |
394 ms |
26960 KB |
Output is correct |
17 |
Correct |
373 ms |
26964 KB |
Output is correct |
18 |
Correct |
369 ms |
27032 KB |
Output is correct |
19 |
Correct |
379 ms |
27220 KB |
Output is correct |
20 |
Correct |
411 ms |
26964 KB |
Output is correct |
21 |
Correct |
362 ms |
26852 KB |
Output is correct |
22 |
Correct |
387 ms |
27732 KB |
Output is correct |
23 |
Correct |
377 ms |
27732 KB |
Output is correct |
24 |
Correct |
395 ms |
27728 KB |
Output is correct |
25 |
Correct |
382 ms |
27732 KB |
Output is correct |
26 |
Correct |
371 ms |
27732 KB |
Output is correct |
27 |
Correct |
428 ms |
27724 KB |
Output is correct |
28 |
Correct |
365 ms |
27752 KB |
Output is correct |
29 |
Correct |
336 ms |
27728 KB |
Output is correct |
30 |
Correct |
375 ms |
27752 KB |
Output is correct |
31 |
Correct |
373 ms |
27728 KB |
Output is correct |
32 |
Correct |
386 ms |
27732 KB |
Output is correct |
33 |
Correct |
374 ms |
27732 KB |
Output is correct |
34 |
Correct |
392 ms |
27728 KB |
Output is correct |
35 |
Correct |
358 ms |
27732 KB |
Output is correct |
36 |
Correct |
356 ms |
27728 KB |
Output is correct |
37 |
Correct |
367 ms |
27616 KB |
Output is correct |
38 |
Correct |
342 ms |
27732 KB |
Output is correct |
39 |
Correct |
343 ms |
27728 KB |
Output is correct |
40 |
Correct |
354 ms |
27732 KB |
Output is correct |
41 |
Correct |
348 ms |
27724 KB |
Output is correct |
42 |
Correct |
339 ms |
27988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
378 ms |
26964 KB |
Output is correct |
2 |
Correct |
372 ms |
27036 KB |
Output is correct |
3 |
Correct |
371 ms |
26964 KB |
Output is correct |
4 |
Correct |
354 ms |
26956 KB |
Output is correct |
5 |
Correct |
363 ms |
26960 KB |
Output is correct |
6 |
Correct |
370 ms |
26960 KB |
Output is correct |
7 |
Correct |
374 ms |
27224 KB |
Output is correct |
8 |
Correct |
393 ms |
26964 KB |
Output is correct |
9 |
Correct |
377 ms |
26964 KB |
Output is correct |
10 |
Correct |
346 ms |
26912 KB |
Output is correct |
11 |
Correct |
367 ms |
26876 KB |
Output is correct |
12 |
Correct |
397 ms |
26908 KB |
Output is correct |
13 |
Correct |
365 ms |
26964 KB |
Output is correct |
14 |
Correct |
351 ms |
26960 KB |
Output is correct |
15 |
Correct |
381 ms |
26960 KB |
Output is correct |
16 |
Correct |
394 ms |
26960 KB |
Output is correct |
17 |
Correct |
373 ms |
26964 KB |
Output is correct |
18 |
Correct |
369 ms |
27032 KB |
Output is correct |
19 |
Correct |
379 ms |
27220 KB |
Output is correct |
20 |
Correct |
411 ms |
26964 KB |
Output is correct |
21 |
Correct |
362 ms |
26852 KB |
Output is correct |
22 |
Correct |
387 ms |
27732 KB |
Output is correct |
23 |
Correct |
377 ms |
27732 KB |
Output is correct |
24 |
Correct |
395 ms |
27728 KB |
Output is correct |
25 |
Correct |
382 ms |
27732 KB |
Output is correct |
26 |
Correct |
371 ms |
27732 KB |
Output is correct |
27 |
Correct |
428 ms |
27724 KB |
Output is correct |
28 |
Correct |
365 ms |
27752 KB |
Output is correct |
29 |
Correct |
336 ms |
27728 KB |
Output is correct |
30 |
Correct |
375 ms |
27752 KB |
Output is correct |
31 |
Correct |
373 ms |
27728 KB |
Output is correct |
32 |
Correct |
386 ms |
27732 KB |
Output is correct |
33 |
Correct |
374 ms |
27732 KB |
Output is correct |
34 |
Correct |
392 ms |
27728 KB |
Output is correct |
35 |
Correct |
358 ms |
27732 KB |
Output is correct |
36 |
Correct |
356 ms |
27728 KB |
Output is correct |
37 |
Correct |
367 ms |
27616 KB |
Output is correct |
38 |
Correct |
342 ms |
27732 KB |
Output is correct |
39 |
Correct |
343 ms |
27728 KB |
Output is correct |
40 |
Correct |
354 ms |
27732 KB |
Output is correct |
41 |
Correct |
348 ms |
27724 KB |
Output is correct |
42 |
Correct |
339 ms |
27988 KB |
Output is correct |
43 |
Correct |
341 ms |
27988 KB |
Output is correct |
44 |
Correct |
345 ms |
27984 KB |
Output is correct |
45 |
Correct |
335 ms |
27860 KB |
Output is correct |
46 |
Correct |
336 ms |
27844 KB |
Output is correct |
47 |
Correct |
357 ms |
27748 KB |
Output is correct |
48 |
Correct |
365 ms |
27732 KB |
Output is correct |
49 |
Correct |
344 ms |
27928 KB |
Output is correct |
50 |
Correct |
324 ms |
27732 KB |
Output is correct |
51 |
Correct |
362 ms |
27888 KB |
Output is correct |
52 |
Correct |
362 ms |
27728 KB |
Output is correct |
53 |
Correct |
338 ms |
27756 KB |
Output is correct |
54 |
Correct |
350 ms |
27732 KB |
Output is correct |
55 |
Correct |
353 ms |
27732 KB |
Output is correct |
56 |
Correct |
348 ms |
27836 KB |
Output is correct |
57 |
Correct |
344 ms |
27732 KB |
Output is correct |
58 |
Correct |
365 ms |
27732 KB |
Output is correct |
59 |
Correct |
378 ms |
27748 KB |
Output is correct |
60 |
Correct |
374 ms |
27888 KB |
Output is correct |
61 |
Correct |
346 ms |
27976 KB |
Output is correct |
62 |
Correct |
393 ms |
27736 KB |
Output is correct |
63 |
Correct |
345 ms |
27728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
378 ms |
26964 KB |
Output is correct |
2 |
Correct |
372 ms |
27036 KB |
Output is correct |
3 |
Correct |
371 ms |
26964 KB |
Output is correct |
4 |
Correct |
354 ms |
26956 KB |
Output is correct |
5 |
Correct |
363 ms |
26960 KB |
Output is correct |
6 |
Correct |
370 ms |
26960 KB |
Output is correct |
7 |
Correct |
374 ms |
27224 KB |
Output is correct |
8 |
Correct |
393 ms |
26964 KB |
Output is correct |
9 |
Correct |
377 ms |
26964 KB |
Output is correct |
10 |
Correct |
346 ms |
26912 KB |
Output is correct |
11 |
Correct |
367 ms |
26876 KB |
Output is correct |
12 |
Correct |
397 ms |
26908 KB |
Output is correct |
13 |
Correct |
365 ms |
26964 KB |
Output is correct |
14 |
Correct |
351 ms |
26960 KB |
Output is correct |
15 |
Correct |
381 ms |
26960 KB |
Output is correct |
16 |
Correct |
394 ms |
26960 KB |
Output is correct |
17 |
Correct |
373 ms |
26964 KB |
Output is correct |
18 |
Correct |
369 ms |
27032 KB |
Output is correct |
19 |
Correct |
379 ms |
27220 KB |
Output is correct |
20 |
Correct |
411 ms |
26964 KB |
Output is correct |
21 |
Correct |
362 ms |
26852 KB |
Output is correct |
22 |
Correct |
387 ms |
27732 KB |
Output is correct |
23 |
Correct |
377 ms |
27732 KB |
Output is correct |
24 |
Correct |
395 ms |
27728 KB |
Output is correct |
25 |
Correct |
382 ms |
27732 KB |
Output is correct |
26 |
Correct |
371 ms |
27732 KB |
Output is correct |
27 |
Correct |
428 ms |
27724 KB |
Output is correct |
28 |
Correct |
365 ms |
27752 KB |
Output is correct |
29 |
Correct |
336 ms |
27728 KB |
Output is correct |
30 |
Correct |
375 ms |
27752 KB |
Output is correct |
31 |
Correct |
373 ms |
27728 KB |
Output is correct |
32 |
Correct |
386 ms |
27732 KB |
Output is correct |
33 |
Correct |
374 ms |
27732 KB |
Output is correct |
34 |
Correct |
392 ms |
27728 KB |
Output is correct |
35 |
Correct |
358 ms |
27732 KB |
Output is correct |
36 |
Correct |
356 ms |
27728 KB |
Output is correct |
37 |
Correct |
367 ms |
27616 KB |
Output is correct |
38 |
Correct |
342 ms |
27732 KB |
Output is correct |
39 |
Correct |
343 ms |
27728 KB |
Output is correct |
40 |
Correct |
354 ms |
27732 KB |
Output is correct |
41 |
Correct |
348 ms |
27724 KB |
Output is correct |
42 |
Correct |
339 ms |
27988 KB |
Output is correct |
43 |
Correct |
341 ms |
27988 KB |
Output is correct |
44 |
Correct |
345 ms |
27984 KB |
Output is correct |
45 |
Correct |
335 ms |
27860 KB |
Output is correct |
46 |
Correct |
336 ms |
27844 KB |
Output is correct |
47 |
Correct |
357 ms |
27748 KB |
Output is correct |
48 |
Correct |
365 ms |
27732 KB |
Output is correct |
49 |
Correct |
344 ms |
27928 KB |
Output is correct |
50 |
Correct |
324 ms |
27732 KB |
Output is correct |
51 |
Correct |
362 ms |
27888 KB |
Output is correct |
52 |
Correct |
362 ms |
27728 KB |
Output is correct |
53 |
Correct |
338 ms |
27756 KB |
Output is correct |
54 |
Correct |
350 ms |
27732 KB |
Output is correct |
55 |
Correct |
353 ms |
27732 KB |
Output is correct |
56 |
Correct |
348 ms |
27836 KB |
Output is correct |
57 |
Correct |
344 ms |
27732 KB |
Output is correct |
58 |
Correct |
365 ms |
27732 KB |
Output is correct |
59 |
Correct |
378 ms |
27748 KB |
Output is correct |
60 |
Correct |
374 ms |
27888 KB |
Output is correct |
61 |
Correct |
346 ms |
27976 KB |
Output is correct |
62 |
Correct |
393 ms |
27736 KB |
Output is correct |
63 |
Correct |
345 ms |
27728 KB |
Output is correct |
64 |
Incorrect |
351 ms |
27988 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |