#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
ll ct[200][200];
int ch[4];
string s1 = "abcdef";
string s2 = "abcdefghijklmnop";
string s3 = "abcdefghijklmnopABCDEFGHIJKLMNOP";
string s4 = "abcdefghijklmnopABCDEFGHIJKLMNOP";
unordered_map<int, ll> m;
ll conv(ll b, ll c, ll d) {
return 40000LL * b + 200LL * c + d;
}
ll rec(int i) {
if(i == 4) {
ll ans = 1;
ans *= m[conv(ch[0], ch[1], ch[2])];
if(ans > MOD) ans %= MOD;
ans *= m[conv(ch[0], ch[1], ch[3])];
if(ans > MOD) ans %= MOD;
ans *= m[conv(ch[0], ch[2], ch[3])];
if(ans > MOD) ans %= MOD;
ans *= m[conv(ch[1], ch[2], ch[3])];
if(ans > MOD) ans %= MOD;
if(ans) cout << ch[0] << ' ' << ch[1] << ' ' << ch[2] << ' ' << ch[3] << ' ' << ans << '\n';
return ans;
}
ll ans = 0;
int k = 0;
if(i) {
for(int j = 0; j < s4.size(); j++) {
if(s4.at(j) == ch[i-1]) k = j;
}
}
for(int j = k; j < s4.size(); j++) {
ch[i] = (int)s4.at(j);
ans += rec(i+1);
if(ans > MOD) ans %= MOD;
}
return ans;
}
ll perms(int a, int b, int c, int d) {
if(a == b && b == c && c == d) return 1;
if(a == b && b == c) return 4;
if(b == c && c == d) return 4;
if(a == b && c == d) return 6;
if(a == b || b == c || c == d) return 12;
return 24;
}
int main() {
int n;
cin >> n;
vector<string> words(n), v;
set<string> s;
for(int i = 0; i < n; i++) {
cin >> words[i];
}
ll ans = 0;
for(int x = 3; x <= 10; x++) {
for(int i = 0; i < n; i++) {
if(words[i].size() == x) v.push_back(words[i]);
}
for(int i = 0; i < v.size(); i++) {
if(s.count(v[i])) continue;
s.insert(v[i]);
ct[v[i][0]][v[i][v[i].size()-1]]++;
// Other side
reverse(v[i].begin(), v[i].end());
if(s.count(v[i])) continue;
s.insert(v[i]);
ct[v[i][0]][v[i][v[i].size()-1]]++;
}
for(int i = 0; i < s4.size(); i++) {
for(int j = i; j < s4.size(); j++) {
for(int k = j; k < s4.size(); k++) {
for(int l = 0; l < s4.size(); l++) {
int w = s4[i], x = s4[j], y = s4[k], z = s4[l];
ll g = (ct[w][z] * ct[x][z] * ct[y][z]) % MOD;
if(g == 0) continue;
m[conv(w, x, y)] += g;
m[conv(w, x, y)] %= MOD;
}
}
}
}
for(int i = 0; i < s4.size(); i++) {
for(int j = i; j < s4.size(); j++) {
for(int k = j; k < s4.size(); k++) {
for(int l = k; l < s4.size(); l++) {
ll tot = 1;
tot *= m[conv(s4[i], s4[j], s4[k])];
tot *= m[conv(s4[i], s4[j], s4[l])];
tot %= MOD;
tot *= m[conv(s4[i], s4[k], s4[l])];
tot %= MOD;
tot *= m[conv(s4[j], s4[k], s4[l])];
tot %= MOD;
tot *= perms(i, j, k, l);
ans += tot;
ans %= MOD;
}
}
}
}
for(int i = 0; i < v.size(); i++) {
ct[v[i][0]][v[i][v[i].size()-1]] = 0;
reverse(v[i].begin(), v[i].end());
ct[v[i][0]][v[i][v[i].size()-1]] = 0;
}
vector<string>().swap(v);
set<string>().swap(s);
unordered_map<int, ll>().swap(m);
}
cout << ans << '\n';
}
Compilation message
cubeword.cpp: In function 'll rec(int)':
cubeword.cpp:39:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int j = 0; j < s4.size(); j++) {
| ~~^~~~~~~~~~~
cubeword.cpp:43:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int j = k; j < s4.size(); j++) {
| ~~^~~~~~~~~~~
cubeword.cpp: In function 'int main()':
cubeword.cpp:71:32: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
71 | if(words[i].size() == x) v.push_back(words[i]);
| ~~~~~~~~~~~~~~~~^~~~
cubeword.cpp:73:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
cubeword.cpp:76:23: warning: array subscript has type 'char' [-Wchar-subscripts]
76 | ct[v[i][0]][v[i][v[i].size()-1]]++;
| ^
cubeword.cpp:76:44: warning: array subscript has type 'char' [-Wchar-subscripts]
76 | ct[v[i][0]][v[i][v[i].size()-1]]++;
| ^
cubeword.cpp:81:23: warning: array subscript has type 'char' [-Wchar-subscripts]
81 | ct[v[i][0]][v[i][v[i].size()-1]]++;
| ^
cubeword.cpp:81:44: warning: array subscript has type 'char' [-Wchar-subscripts]
81 | ct[v[i][0]][v[i][v[i].size()-1]]++;
| ^
cubeword.cpp:83:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for(int i = 0; i < s4.size(); i++) {
| ~~^~~~~~~~~~~
cubeword.cpp:84:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for(int j = i; j < s4.size(); j++) {
| ~~^~~~~~~~~~~
cubeword.cpp:85:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int k = j; k < s4.size(); k++) {
| ~~^~~~~~~~~~~
cubeword.cpp:86:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(int l = 0; l < s4.size(); l++) {
| ~~^~~~~~~~~~~
cubeword.cpp:96:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for(int i = 0; i < s4.size(); i++) {
| ~~^~~~~~~~~~~
cubeword.cpp:97:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for(int j = i; j < s4.size(); j++) {
| ~~^~~~~~~~~~~
cubeword.cpp:98:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | for(int k = j; k < s4.size(); k++) {
| ~~^~~~~~~~~~~
cubeword.cpp:99:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
99 | for(int l = k; l < s4.size(); l++) {
| ~~^~~~~~~~~~~
cubeword.cpp:115:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | for(int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
cubeword.cpp:116:23: warning: array subscript has type 'char' [-Wchar-subscripts]
116 | ct[v[i][0]][v[i][v[i].size()-1]] = 0;
| ^
cubeword.cpp:116:44: warning: array subscript has type 'char' [-Wchar-subscripts]
116 | ct[v[i][0]][v[i][v[i].size()-1]] = 0;
| ^
cubeword.cpp:118:23: warning: array subscript has type 'char' [-Wchar-subscripts]
118 | ct[v[i][0]][v[i][v[i].size()-1]] = 0;
| ^
cubeword.cpp:118:44: warning: array subscript has type 'char' [-Wchar-subscripts]
118 | ct[v[i][0]][v[i][v[i].size()-1]] = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
8548 KB |
Output is correct |
2 |
Correct |
160 ms |
8148 KB |
Output is correct |
3 |
Correct |
152 ms |
8496 KB |
Output is correct |
4 |
Correct |
155 ms |
8568 KB |
Output is correct |
5 |
Correct |
170 ms |
8596 KB |
Output is correct |
6 |
Correct |
161 ms |
8560 KB |
Output is correct |
7 |
Correct |
182 ms |
8540 KB |
Output is correct |
8 |
Correct |
150 ms |
8524 KB |
Output is correct |
9 |
Correct |
165 ms |
8532 KB |
Output is correct |
10 |
Correct |
160 ms |
8588 KB |
Output is correct |
11 |
Correct |
175 ms |
8484 KB |
Output is correct |
12 |
Correct |
167 ms |
8748 KB |
Output is correct |
13 |
Correct |
151 ms |
8504 KB |
Output is correct |
14 |
Correct |
190 ms |
8572 KB |
Output is correct |
15 |
Correct |
150 ms |
8588 KB |
Output is correct |
16 |
Correct |
154 ms |
8588 KB |
Output is correct |
17 |
Correct |
197 ms |
8564 KB |
Output is correct |
18 |
Correct |
162 ms |
8540 KB |
Output is correct |
19 |
Correct |
156 ms |
8508 KB |
Output is correct |
20 |
Correct |
163 ms |
8580 KB |
Output is correct |
21 |
Correct |
155 ms |
8584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
8548 KB |
Output is correct |
2 |
Correct |
160 ms |
8148 KB |
Output is correct |
3 |
Correct |
152 ms |
8496 KB |
Output is correct |
4 |
Correct |
155 ms |
8568 KB |
Output is correct |
5 |
Correct |
170 ms |
8596 KB |
Output is correct |
6 |
Correct |
161 ms |
8560 KB |
Output is correct |
7 |
Correct |
182 ms |
8540 KB |
Output is correct |
8 |
Correct |
150 ms |
8524 KB |
Output is correct |
9 |
Correct |
165 ms |
8532 KB |
Output is correct |
10 |
Correct |
160 ms |
8588 KB |
Output is correct |
11 |
Correct |
175 ms |
8484 KB |
Output is correct |
12 |
Correct |
167 ms |
8748 KB |
Output is correct |
13 |
Correct |
151 ms |
8504 KB |
Output is correct |
14 |
Correct |
190 ms |
8572 KB |
Output is correct |
15 |
Correct |
150 ms |
8588 KB |
Output is correct |
16 |
Correct |
154 ms |
8588 KB |
Output is correct |
17 |
Correct |
197 ms |
8564 KB |
Output is correct |
18 |
Correct |
162 ms |
8540 KB |
Output is correct |
19 |
Correct |
156 ms |
8508 KB |
Output is correct |
20 |
Correct |
163 ms |
8580 KB |
Output is correct |
21 |
Correct |
155 ms |
8584 KB |
Output is correct |
22 |
Correct |
154 ms |
7216 KB |
Output is correct |
23 |
Correct |
167 ms |
7192 KB |
Output is correct |
24 |
Correct |
151 ms |
7096 KB |
Output is correct |
25 |
Correct |
163 ms |
7204 KB |
Output is correct |
26 |
Correct |
164 ms |
7212 KB |
Output is correct |
27 |
Correct |
151 ms |
7208 KB |
Output is correct |
28 |
Correct |
172 ms |
7192 KB |
Output is correct |
29 |
Correct |
151 ms |
7164 KB |
Output is correct |
30 |
Correct |
158 ms |
7196 KB |
Output is correct |
31 |
Correct |
172 ms |
7320 KB |
Output is correct |
32 |
Correct |
154 ms |
7196 KB |
Output is correct |
33 |
Correct |
155 ms |
7192 KB |
Output is correct |
34 |
Correct |
155 ms |
7212 KB |
Output is correct |
35 |
Correct |
164 ms |
7124 KB |
Output is correct |
36 |
Correct |
161 ms |
7096 KB |
Output is correct |
37 |
Correct |
150 ms |
7208 KB |
Output is correct |
38 |
Correct |
157 ms |
7192 KB |
Output is correct |
39 |
Correct |
157 ms |
7176 KB |
Output is correct |
40 |
Correct |
150 ms |
7196 KB |
Output is correct |
41 |
Correct |
183 ms |
7204 KB |
Output is correct |
42 |
Correct |
161 ms |
7096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
8548 KB |
Output is correct |
2 |
Correct |
160 ms |
8148 KB |
Output is correct |
3 |
Correct |
152 ms |
8496 KB |
Output is correct |
4 |
Correct |
155 ms |
8568 KB |
Output is correct |
5 |
Correct |
170 ms |
8596 KB |
Output is correct |
6 |
Correct |
161 ms |
8560 KB |
Output is correct |
7 |
Correct |
182 ms |
8540 KB |
Output is correct |
8 |
Correct |
150 ms |
8524 KB |
Output is correct |
9 |
Correct |
165 ms |
8532 KB |
Output is correct |
10 |
Correct |
160 ms |
8588 KB |
Output is correct |
11 |
Correct |
175 ms |
8484 KB |
Output is correct |
12 |
Correct |
167 ms |
8748 KB |
Output is correct |
13 |
Correct |
151 ms |
8504 KB |
Output is correct |
14 |
Correct |
190 ms |
8572 KB |
Output is correct |
15 |
Correct |
150 ms |
8588 KB |
Output is correct |
16 |
Correct |
154 ms |
8588 KB |
Output is correct |
17 |
Correct |
197 ms |
8564 KB |
Output is correct |
18 |
Correct |
162 ms |
8540 KB |
Output is correct |
19 |
Correct |
156 ms |
8508 KB |
Output is correct |
20 |
Correct |
163 ms |
8580 KB |
Output is correct |
21 |
Correct |
155 ms |
8584 KB |
Output is correct |
22 |
Correct |
154 ms |
7216 KB |
Output is correct |
23 |
Correct |
167 ms |
7192 KB |
Output is correct |
24 |
Correct |
151 ms |
7096 KB |
Output is correct |
25 |
Correct |
163 ms |
7204 KB |
Output is correct |
26 |
Correct |
164 ms |
7212 KB |
Output is correct |
27 |
Correct |
151 ms |
7208 KB |
Output is correct |
28 |
Correct |
172 ms |
7192 KB |
Output is correct |
29 |
Correct |
151 ms |
7164 KB |
Output is correct |
30 |
Correct |
158 ms |
7196 KB |
Output is correct |
31 |
Correct |
172 ms |
7320 KB |
Output is correct |
32 |
Correct |
154 ms |
7196 KB |
Output is correct |
33 |
Correct |
155 ms |
7192 KB |
Output is correct |
34 |
Correct |
155 ms |
7212 KB |
Output is correct |
35 |
Correct |
164 ms |
7124 KB |
Output is correct |
36 |
Correct |
161 ms |
7096 KB |
Output is correct |
37 |
Correct |
150 ms |
7208 KB |
Output is correct |
38 |
Correct |
157 ms |
7192 KB |
Output is correct |
39 |
Correct |
157 ms |
7176 KB |
Output is correct |
40 |
Correct |
150 ms |
7196 KB |
Output is correct |
41 |
Correct |
183 ms |
7204 KB |
Output is correct |
42 |
Correct |
161 ms |
7096 KB |
Output is correct |
43 |
Correct |
190 ms |
7020 KB |
Output is correct |
44 |
Correct |
209 ms |
7008 KB |
Output is correct |
45 |
Correct |
193 ms |
6928 KB |
Output is correct |
46 |
Correct |
191 ms |
7016 KB |
Output is correct |
47 |
Correct |
202 ms |
7044 KB |
Output is correct |
48 |
Correct |
188 ms |
7016 KB |
Output is correct |
49 |
Correct |
214 ms |
7000 KB |
Output is correct |
50 |
Correct |
194 ms |
7272 KB |
Output is correct |
51 |
Correct |
196 ms |
7020 KB |
Output is correct |
52 |
Correct |
191 ms |
6944 KB |
Output is correct |
53 |
Correct |
204 ms |
6904 KB |
Output is correct |
54 |
Correct |
199 ms |
6916 KB |
Output is correct |
55 |
Correct |
191 ms |
6924 KB |
Output is correct |
56 |
Correct |
217 ms |
6964 KB |
Output is correct |
57 |
Correct |
204 ms |
6996 KB |
Output is correct |
58 |
Correct |
209 ms |
6900 KB |
Output is correct |
59 |
Correct |
209 ms |
7020 KB |
Output is correct |
60 |
Correct |
191 ms |
7020 KB |
Output is correct |
61 |
Correct |
191 ms |
7048 KB |
Output is correct |
62 |
Correct |
216 ms |
6968 KB |
Output is correct |
63 |
Correct |
186 ms |
7040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
8548 KB |
Output is correct |
2 |
Correct |
160 ms |
8148 KB |
Output is correct |
3 |
Correct |
152 ms |
8496 KB |
Output is correct |
4 |
Correct |
155 ms |
8568 KB |
Output is correct |
5 |
Correct |
170 ms |
8596 KB |
Output is correct |
6 |
Correct |
161 ms |
8560 KB |
Output is correct |
7 |
Correct |
182 ms |
8540 KB |
Output is correct |
8 |
Correct |
150 ms |
8524 KB |
Output is correct |
9 |
Correct |
165 ms |
8532 KB |
Output is correct |
10 |
Correct |
160 ms |
8588 KB |
Output is correct |
11 |
Correct |
175 ms |
8484 KB |
Output is correct |
12 |
Correct |
167 ms |
8748 KB |
Output is correct |
13 |
Correct |
151 ms |
8504 KB |
Output is correct |
14 |
Correct |
190 ms |
8572 KB |
Output is correct |
15 |
Correct |
150 ms |
8588 KB |
Output is correct |
16 |
Correct |
154 ms |
8588 KB |
Output is correct |
17 |
Correct |
197 ms |
8564 KB |
Output is correct |
18 |
Correct |
162 ms |
8540 KB |
Output is correct |
19 |
Correct |
156 ms |
8508 KB |
Output is correct |
20 |
Correct |
163 ms |
8580 KB |
Output is correct |
21 |
Correct |
155 ms |
8584 KB |
Output is correct |
22 |
Correct |
154 ms |
7216 KB |
Output is correct |
23 |
Correct |
167 ms |
7192 KB |
Output is correct |
24 |
Correct |
151 ms |
7096 KB |
Output is correct |
25 |
Correct |
163 ms |
7204 KB |
Output is correct |
26 |
Correct |
164 ms |
7212 KB |
Output is correct |
27 |
Correct |
151 ms |
7208 KB |
Output is correct |
28 |
Correct |
172 ms |
7192 KB |
Output is correct |
29 |
Correct |
151 ms |
7164 KB |
Output is correct |
30 |
Correct |
158 ms |
7196 KB |
Output is correct |
31 |
Correct |
172 ms |
7320 KB |
Output is correct |
32 |
Correct |
154 ms |
7196 KB |
Output is correct |
33 |
Correct |
155 ms |
7192 KB |
Output is correct |
34 |
Correct |
155 ms |
7212 KB |
Output is correct |
35 |
Correct |
164 ms |
7124 KB |
Output is correct |
36 |
Correct |
161 ms |
7096 KB |
Output is correct |
37 |
Correct |
150 ms |
7208 KB |
Output is correct |
38 |
Correct |
157 ms |
7192 KB |
Output is correct |
39 |
Correct |
157 ms |
7176 KB |
Output is correct |
40 |
Correct |
150 ms |
7196 KB |
Output is correct |
41 |
Correct |
183 ms |
7204 KB |
Output is correct |
42 |
Correct |
161 ms |
7096 KB |
Output is correct |
43 |
Correct |
190 ms |
7020 KB |
Output is correct |
44 |
Correct |
209 ms |
7008 KB |
Output is correct |
45 |
Correct |
193 ms |
6928 KB |
Output is correct |
46 |
Correct |
191 ms |
7016 KB |
Output is correct |
47 |
Correct |
202 ms |
7044 KB |
Output is correct |
48 |
Correct |
188 ms |
7016 KB |
Output is correct |
49 |
Correct |
214 ms |
7000 KB |
Output is correct |
50 |
Correct |
194 ms |
7272 KB |
Output is correct |
51 |
Correct |
196 ms |
7020 KB |
Output is correct |
52 |
Correct |
191 ms |
6944 KB |
Output is correct |
53 |
Correct |
204 ms |
6904 KB |
Output is correct |
54 |
Correct |
199 ms |
6916 KB |
Output is correct |
55 |
Correct |
191 ms |
6924 KB |
Output is correct |
56 |
Correct |
217 ms |
6964 KB |
Output is correct |
57 |
Correct |
204 ms |
6996 KB |
Output is correct |
58 |
Correct |
209 ms |
6900 KB |
Output is correct |
59 |
Correct |
209 ms |
7020 KB |
Output is correct |
60 |
Correct |
191 ms |
7020 KB |
Output is correct |
61 |
Correct |
191 ms |
7048 KB |
Output is correct |
62 |
Correct |
216 ms |
6968 KB |
Output is correct |
63 |
Correct |
186 ms |
7040 KB |
Output is correct |
64 |
Incorrect |
203 ms |
7020 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |