#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
const int MOD = 998244353LL;
const int MAX_N =62LL;
int nbP[MAX_N][MAX_N];
int D[MAX_N][MAX_N][MAX_N];
int RES = 0;
bool is_palindrome(string s){
bool ok = true;
for(int i = 0; i<(s.size()+1)/2; i++){
ok &= (s[i] == s[s.size()-i-1]);
}
return ok;
}
int mexp(int a, int b){
int res = 1;
vector<int>pows(1, a);
for(int i= 1; i<35; i++){
pows.push_back((pows.back()*pows.back())%MOD);
}
for(int i = 0; i<35; i++){
if(0LL!=((1LL<<i)&b)){
res = (res * pows[i])%MOD;
}
}
return res;
}
unordered_map<int, int> inv;
int modinv(int a){
if(inv.find(a)!=inv.end()){
return inv[a];
}
int b= mexp(a, MOD-2);
inv[a] = b;
assert((a*b)%MOD == 1);
return b;
}
map<char, int> assign;
void construct_table(){
for(char c= 'a'; c<='z'; c++){
assign[c] = assign.size();
}
for(char c= 'A'; c<='Z'; c++){
assign[c] = assign.size();
}
for(char c= '0'; c<='9'; c++){
assign[c] = assign.size();
}
}
vector<int> transform(string s){
vector<int> res(s.size());
for(int i = 0; i<s.size(); i++){
res[i] = assign[s[i]];
}
return res;
}
int fact(int u){
if(u == 0){
return 1;
}
return fact(u-1)*u;
}
int nbperm(vector<int>& v){
int res= 24;
int streak =1;
for(int i = 1; i<v.size(); i++){
if(v[i] == v[i-1]){
streak++;
res/=streak;
}
else{
streak=1;
}
}
return res;
}
int prod(vector<int> v){
int res= 1;
for(auto e: v){
res= (res*e)%MOD;
}
return res;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin>>N;
vector<unordered_set<string>> words(11);
construct_table();
for(int i = 0; i<N; i++){
string s;
cin>>s;
if(is_palindrome(s)){
words[s.size()].insert(s);
}
else{
words[s.size()].insert(s);
reverse(s.begin(), s.end());
words[s.size()].insert(s);
}
}
//vector<pair<int, vector<int>>> colorings= iterate_all(8,6);
for(int len = 3; len<=10; len++){
fill(&nbP[0][0], &nbP[MAX_N][0], 0);
fill(&D[0][0][0], &D[MAX_N][0][0], 0);
for(auto e: words[len]){
auto v = transform(e);
int a= v[0];
int b= v.back();
nbP[a][b]++;
}
for(int i = 0; i<MAX_N; i++){
for(int j = i; j<MAX_N; j++){
for(int k = j; k<MAX_N; k++){
for(int l = 0; l<MAX_N; l++){
D[i][j][k] = (D[i][j][k]+((nbP[l][i]*nbP[l][j])%MOD*nbP[l][k])%MOD)%MOD;
}
}
}
}
int cur= 0;
int coef = 24;
vector<int> cv;
for(int i = 0; i<MAX_N; i++){
cv.push_back(i);
for(int j = i; j<MAX_N; j++){
cv.push_back(j);
for(int k = j; k<MAX_N; k++){
cv.push_back(k);
for(int h = k; h<MAX_N; h++){
cv.push_back(h);
int coef = nbperm(cv);
coef = (coef*D[i][j][k])%MOD;
coef = (coef*D[j][k][h])%MOD;
coef = (coef*D[i][k][h])%MOD;
coef = (coef*D[i][j][h])%MOD;
RES =(RES+coef)%MOD;
cv.pop_back();
}
cv.pop_back();
}
cv.pop_back();
}
cv.pop_back();
}
}
cout<<RES<<endl;
}
Compilation message
cubeword.cpp: In function 'bool is_palindrome(std::string)':
cubeword.cpp:16:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for(int i = 0; i<(s.size()+1)/2; i++){
| ~^~~~~~~~~~~~~~~
cubeword.cpp: In function 'std::vector<long long int> transform(std::string)':
cubeword.cpp:67:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i = 0; i<s.size(); i++){
| ~^~~~~~~~~
cubeword.cpp: In function 'long long int nbperm(std::vector<long long int>&)':
cubeword.cpp:84:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for(int i = 1; i<v.size(); i++){
| ~^~~~~~~~~
cubeword.cpp: In function 'int main()':
cubeword.cpp:147:13: warning: unused variable 'cur' [-Wunused-variable]
147 | int cur= 0;
| ^~~
cubeword.cpp:148:13: warning: unused variable 'coef' [-Wunused-variable]
148 | int coef = 24;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
197 ms |
16408 KB |
Output is correct |
2 |
Correct |
203 ms |
16416 KB |
Output is correct |
3 |
Correct |
203 ms |
16416 KB |
Output is correct |
4 |
Correct |
202 ms |
16416 KB |
Output is correct |
5 |
Correct |
196 ms |
16424 KB |
Output is correct |
6 |
Correct |
196 ms |
16412 KB |
Output is correct |
7 |
Correct |
199 ms |
16416 KB |
Output is correct |
8 |
Correct |
190 ms |
16408 KB |
Output is correct |
9 |
Correct |
200 ms |
16464 KB |
Output is correct |
10 |
Correct |
196 ms |
16424 KB |
Output is correct |
11 |
Correct |
209 ms |
16476 KB |
Output is correct |
12 |
Correct |
210 ms |
16236 KB |
Output is correct |
13 |
Correct |
197 ms |
16484 KB |
Output is correct |
14 |
Correct |
201 ms |
16412 KB |
Output is correct |
15 |
Correct |
205 ms |
16484 KB |
Output is correct |
16 |
Correct |
208 ms |
16464 KB |
Output is correct |
17 |
Correct |
229 ms |
16412 KB |
Output is correct |
18 |
Correct |
207 ms |
16668 KB |
Output is correct |
19 |
Correct |
203 ms |
16412 KB |
Output is correct |
20 |
Correct |
195 ms |
16480 KB |
Output is correct |
21 |
Correct |
205 ms |
16228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
197 ms |
16408 KB |
Output is correct |
2 |
Correct |
203 ms |
16416 KB |
Output is correct |
3 |
Correct |
203 ms |
16416 KB |
Output is correct |
4 |
Correct |
202 ms |
16416 KB |
Output is correct |
5 |
Correct |
196 ms |
16424 KB |
Output is correct |
6 |
Correct |
196 ms |
16412 KB |
Output is correct |
7 |
Correct |
199 ms |
16416 KB |
Output is correct |
8 |
Correct |
190 ms |
16408 KB |
Output is correct |
9 |
Correct |
200 ms |
16464 KB |
Output is correct |
10 |
Correct |
196 ms |
16424 KB |
Output is correct |
11 |
Correct |
209 ms |
16476 KB |
Output is correct |
12 |
Correct |
210 ms |
16236 KB |
Output is correct |
13 |
Correct |
197 ms |
16484 KB |
Output is correct |
14 |
Correct |
201 ms |
16412 KB |
Output is correct |
15 |
Correct |
205 ms |
16484 KB |
Output is correct |
16 |
Correct |
208 ms |
16464 KB |
Output is correct |
17 |
Correct |
229 ms |
16412 KB |
Output is correct |
18 |
Correct |
207 ms |
16668 KB |
Output is correct |
19 |
Correct |
203 ms |
16412 KB |
Output is correct |
20 |
Correct |
195 ms |
16480 KB |
Output is correct |
21 |
Correct |
205 ms |
16228 KB |
Output is correct |
22 |
Correct |
213 ms |
17364 KB |
Output is correct |
23 |
Correct |
213 ms |
17368 KB |
Output is correct |
24 |
Correct |
222 ms |
17612 KB |
Output is correct |
25 |
Correct |
212 ms |
17364 KB |
Output is correct |
26 |
Correct |
206 ms |
17364 KB |
Output is correct |
27 |
Correct |
212 ms |
17600 KB |
Output is correct |
28 |
Correct |
257 ms |
17528 KB |
Output is correct |
29 |
Correct |
203 ms |
17628 KB |
Output is correct |
30 |
Correct |
198 ms |
17528 KB |
Output is correct |
31 |
Correct |
211 ms |
17364 KB |
Output is correct |
32 |
Correct |
203 ms |
17532 KB |
Output is correct |
33 |
Correct |
225 ms |
17528 KB |
Output is correct |
34 |
Correct |
208 ms |
17364 KB |
Output is correct |
35 |
Correct |
209 ms |
17620 KB |
Output is correct |
36 |
Correct |
199 ms |
17372 KB |
Output is correct |
37 |
Correct |
249 ms |
17528 KB |
Output is correct |
38 |
Correct |
209 ms |
17616 KB |
Output is correct |
39 |
Correct |
209 ms |
17528 KB |
Output is correct |
40 |
Correct |
208 ms |
17632 KB |
Output is correct |
41 |
Correct |
213 ms |
17620 KB |
Output is correct |
42 |
Correct |
232 ms |
17412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
197 ms |
16408 KB |
Output is correct |
2 |
Correct |
203 ms |
16416 KB |
Output is correct |
3 |
Correct |
203 ms |
16416 KB |
Output is correct |
4 |
Correct |
202 ms |
16416 KB |
Output is correct |
5 |
Correct |
196 ms |
16424 KB |
Output is correct |
6 |
Correct |
196 ms |
16412 KB |
Output is correct |
7 |
Correct |
199 ms |
16416 KB |
Output is correct |
8 |
Correct |
190 ms |
16408 KB |
Output is correct |
9 |
Correct |
200 ms |
16464 KB |
Output is correct |
10 |
Correct |
196 ms |
16424 KB |
Output is correct |
11 |
Correct |
209 ms |
16476 KB |
Output is correct |
12 |
Correct |
210 ms |
16236 KB |
Output is correct |
13 |
Correct |
197 ms |
16484 KB |
Output is correct |
14 |
Correct |
201 ms |
16412 KB |
Output is correct |
15 |
Correct |
205 ms |
16484 KB |
Output is correct |
16 |
Correct |
208 ms |
16464 KB |
Output is correct |
17 |
Correct |
229 ms |
16412 KB |
Output is correct |
18 |
Correct |
207 ms |
16668 KB |
Output is correct |
19 |
Correct |
203 ms |
16412 KB |
Output is correct |
20 |
Correct |
195 ms |
16480 KB |
Output is correct |
21 |
Correct |
205 ms |
16228 KB |
Output is correct |
22 |
Correct |
213 ms |
17364 KB |
Output is correct |
23 |
Correct |
213 ms |
17368 KB |
Output is correct |
24 |
Correct |
222 ms |
17612 KB |
Output is correct |
25 |
Correct |
212 ms |
17364 KB |
Output is correct |
26 |
Correct |
206 ms |
17364 KB |
Output is correct |
27 |
Correct |
212 ms |
17600 KB |
Output is correct |
28 |
Correct |
257 ms |
17528 KB |
Output is correct |
29 |
Correct |
203 ms |
17628 KB |
Output is correct |
30 |
Correct |
198 ms |
17528 KB |
Output is correct |
31 |
Correct |
211 ms |
17364 KB |
Output is correct |
32 |
Correct |
203 ms |
17532 KB |
Output is correct |
33 |
Correct |
225 ms |
17528 KB |
Output is correct |
34 |
Correct |
208 ms |
17364 KB |
Output is correct |
35 |
Correct |
209 ms |
17620 KB |
Output is correct |
36 |
Correct |
199 ms |
17372 KB |
Output is correct |
37 |
Correct |
249 ms |
17528 KB |
Output is correct |
38 |
Correct |
209 ms |
17616 KB |
Output is correct |
39 |
Correct |
209 ms |
17528 KB |
Output is correct |
40 |
Correct |
208 ms |
17632 KB |
Output is correct |
41 |
Correct |
213 ms |
17620 KB |
Output is correct |
42 |
Correct |
232 ms |
17412 KB |
Output is correct |
43 |
Correct |
211 ms |
17628 KB |
Output is correct |
44 |
Correct |
210 ms |
17632 KB |
Output is correct |
45 |
Correct |
227 ms |
17528 KB |
Output is correct |
46 |
Correct |
203 ms |
17652 KB |
Output is correct |
47 |
Correct |
216 ms |
17628 KB |
Output is correct |
48 |
Correct |
217 ms |
17528 KB |
Output is correct |
49 |
Correct |
210 ms |
17540 KB |
Output is correct |
50 |
Correct |
212 ms |
17616 KB |
Output is correct |
51 |
Correct |
225 ms |
17624 KB |
Output is correct |
52 |
Correct |
230 ms |
17700 KB |
Output is correct |
53 |
Correct |
217 ms |
17608 KB |
Output is correct |
54 |
Correct |
203 ms |
17528 KB |
Output is correct |
55 |
Correct |
218 ms |
17784 KB |
Output is correct |
56 |
Correct |
219 ms |
17648 KB |
Output is correct |
57 |
Correct |
204 ms |
17880 KB |
Output is correct |
58 |
Correct |
216 ms |
17652 KB |
Output is correct |
59 |
Correct |
221 ms |
17532 KB |
Output is correct |
60 |
Correct |
205 ms |
17528 KB |
Output is correct |
61 |
Correct |
226 ms |
17528 KB |
Output is correct |
62 |
Correct |
212 ms |
17620 KB |
Output is correct |
63 |
Correct |
220 ms |
17648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
197 ms |
16408 KB |
Output is correct |
2 |
Correct |
203 ms |
16416 KB |
Output is correct |
3 |
Correct |
203 ms |
16416 KB |
Output is correct |
4 |
Correct |
202 ms |
16416 KB |
Output is correct |
5 |
Correct |
196 ms |
16424 KB |
Output is correct |
6 |
Correct |
196 ms |
16412 KB |
Output is correct |
7 |
Correct |
199 ms |
16416 KB |
Output is correct |
8 |
Correct |
190 ms |
16408 KB |
Output is correct |
9 |
Correct |
200 ms |
16464 KB |
Output is correct |
10 |
Correct |
196 ms |
16424 KB |
Output is correct |
11 |
Correct |
209 ms |
16476 KB |
Output is correct |
12 |
Correct |
210 ms |
16236 KB |
Output is correct |
13 |
Correct |
197 ms |
16484 KB |
Output is correct |
14 |
Correct |
201 ms |
16412 KB |
Output is correct |
15 |
Correct |
205 ms |
16484 KB |
Output is correct |
16 |
Correct |
208 ms |
16464 KB |
Output is correct |
17 |
Correct |
229 ms |
16412 KB |
Output is correct |
18 |
Correct |
207 ms |
16668 KB |
Output is correct |
19 |
Correct |
203 ms |
16412 KB |
Output is correct |
20 |
Correct |
195 ms |
16480 KB |
Output is correct |
21 |
Correct |
205 ms |
16228 KB |
Output is correct |
22 |
Correct |
213 ms |
17364 KB |
Output is correct |
23 |
Correct |
213 ms |
17368 KB |
Output is correct |
24 |
Correct |
222 ms |
17612 KB |
Output is correct |
25 |
Correct |
212 ms |
17364 KB |
Output is correct |
26 |
Correct |
206 ms |
17364 KB |
Output is correct |
27 |
Correct |
212 ms |
17600 KB |
Output is correct |
28 |
Correct |
257 ms |
17528 KB |
Output is correct |
29 |
Correct |
203 ms |
17628 KB |
Output is correct |
30 |
Correct |
198 ms |
17528 KB |
Output is correct |
31 |
Correct |
211 ms |
17364 KB |
Output is correct |
32 |
Correct |
203 ms |
17532 KB |
Output is correct |
33 |
Correct |
225 ms |
17528 KB |
Output is correct |
34 |
Correct |
208 ms |
17364 KB |
Output is correct |
35 |
Correct |
209 ms |
17620 KB |
Output is correct |
36 |
Correct |
199 ms |
17372 KB |
Output is correct |
37 |
Correct |
249 ms |
17528 KB |
Output is correct |
38 |
Correct |
209 ms |
17616 KB |
Output is correct |
39 |
Correct |
209 ms |
17528 KB |
Output is correct |
40 |
Correct |
208 ms |
17632 KB |
Output is correct |
41 |
Correct |
213 ms |
17620 KB |
Output is correct |
42 |
Correct |
232 ms |
17412 KB |
Output is correct |
43 |
Correct |
211 ms |
17628 KB |
Output is correct |
44 |
Correct |
210 ms |
17632 KB |
Output is correct |
45 |
Correct |
227 ms |
17528 KB |
Output is correct |
46 |
Correct |
203 ms |
17652 KB |
Output is correct |
47 |
Correct |
216 ms |
17628 KB |
Output is correct |
48 |
Correct |
217 ms |
17528 KB |
Output is correct |
49 |
Correct |
210 ms |
17540 KB |
Output is correct |
50 |
Correct |
212 ms |
17616 KB |
Output is correct |
51 |
Correct |
225 ms |
17624 KB |
Output is correct |
52 |
Correct |
230 ms |
17700 KB |
Output is correct |
53 |
Correct |
217 ms |
17608 KB |
Output is correct |
54 |
Correct |
203 ms |
17528 KB |
Output is correct |
55 |
Correct |
218 ms |
17784 KB |
Output is correct |
56 |
Correct |
219 ms |
17648 KB |
Output is correct |
57 |
Correct |
204 ms |
17880 KB |
Output is correct |
58 |
Correct |
216 ms |
17652 KB |
Output is correct |
59 |
Correct |
221 ms |
17532 KB |
Output is correct |
60 |
Correct |
205 ms |
17528 KB |
Output is correct |
61 |
Correct |
226 ms |
17528 KB |
Output is correct |
62 |
Correct |
212 ms |
17620 KB |
Output is correct |
63 |
Correct |
220 ms |
17648 KB |
Output is correct |
64 |
Correct |
217 ms |
18132 KB |
Output is correct |
65 |
Correct |
212 ms |
18228 KB |
Output is correct |
66 |
Correct |
208 ms |
18136 KB |
Output is correct |
67 |
Correct |
213 ms |
18144 KB |
Output is correct |
68 |
Correct |
220 ms |
18184 KB |
Output is correct |
69 |
Correct |
227 ms |
18140 KB |
Output is correct |
70 |
Correct |
215 ms |
18144 KB |
Output is correct |
71 |
Correct |
215 ms |
18132 KB |
Output is correct |
72 |
Correct |
222 ms |
18232 KB |
Output is correct |
73 |
Correct |
224 ms |
18008 KB |
Output is correct |
74 |
Correct |
225 ms |
18084 KB |
Output is correct |
75 |
Correct |
248 ms |
18228 KB |
Output is correct |
76 |
Correct |
241 ms |
18036 KB |
Output is correct |
77 |
Correct |
213 ms |
18228 KB |
Output is correct |
78 |
Correct |
223 ms |
18224 KB |
Output is correct |
79 |
Correct |
258 ms |
18236 KB |
Output is correct |
80 |
Correct |
227 ms |
18136 KB |
Output is correct |
81 |
Correct |
224 ms |
18136 KB |
Output is correct |
82 |
Correct |
217 ms |
18232 KB |
Output is correct |
83 |
Correct |
219 ms |
18132 KB |
Output is correct |
84 |
Correct |
222 ms |
18168 KB |
Output is correct |