#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<vv> vvv;
typedef pair<ll, ll> p;
typedef vector<p> vp;
typedef vector<vp> vvp;
typedef vector<vvp> vvvp;
typedef pair<ll, p> tri;
typedef vector<tri> vtri;
typedef vector<vtri> vvtri;
typedef vector<vvtri> vvvtri;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
const ll INF = 1e18;
const ll mod = 998244353;
bool isPalindrome(string &str)
{
for (ll i = 0; i < str.size() / 2; i++) if (str[i] != str[str.size() - i - 1]) return false;
return true;
}
ll combinations(ll a, ll b, ll c, ll d)
{
if (a == d) return 1;
if (a == c || b == d) return 4;
if (a == b && c == d) return 6;
if (a == b || c == d || b == c) return 12;
return 24;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll n;
cin >> n;
vector<string> words(n);
for (ll i = 0; i < n; i++) cin >> words[i];
vector<char> characters;
for (ll i= 'a'; i <= 'z'; i++) characters.pb(i);
for (ll i = 'A'; i <= 'Z'; i++) characters.pb(i);
for (ll i = '0'; i <= '9'; i++) characters.pb(i);
map<char, char> charShrink;
for (ll i = 0; i < characters.size(); i++) charShrink[characters[i]] = i;
for (ll i = 0; i < n; i++) for (ll j = 0; j < words[i].size(); j++) words[i][j] = charShrink[words[i][j]];
vector<vector<string>> byLength(11);
set<string> exists;
for (ll i = 0; i < n; i++)
{
reverse(all(words[i]));
if (exists.count(words[i]) > 0) continue;
reverse(all(words[i]));
byLength[words[i].size()].pb(words[i]);
exists.insert(words[i]);
}
ll c = characters.size();
ll res = 0;
for (ll i = 3; i <= 10; i++)
{
vv amt(c, v(c, 0));
for (ll j = 0; j < byLength[i].size(); j++)
{
amt[byLength[i][j][0]][byLength[i][j].back()]++;
if (!isPalindrome(byLength[i][j])) amt[byLength[i][j].back()][byLength[i][j][0]]++;
}
vvv possibilities(c, vv(c, v(c)));
for (ll i = 0; i < c; i++)
{
for (ll j = i; j < c; j++)
{
for (ll k = j; k < c; k++)
{
for (ll l = 0; l < c; l++)
{
possibilities[i][j][k] += ((amt[i][l] * amt[j][l]) % mod) * amt[k][l];
possibilities[i][j][k] %= mod;
}
}
}
}
for (ll corner1 = 0; corner1 < c; corner1++)
{
for (ll corner2 = corner1; corner2 < c; corner2++)
{
for (ll corner3 = corner2; corner3 < c; corner3++)
{
for (ll corner4 = corner3; corner4 < c; corner4++)
{
ll cur = possibilities[corner1][corner2][corner3];
cur = (cur * possibilities[corner1][corner2][corner4]) % mod;
cur = (cur * possibilities[corner1][corner3][corner4]) % mod;
cur = (cur * possibilities[corner2][corner3][corner4]) % mod;
res = (res + cur * combinations(corner1,corner2,corner3,corner4)) % mod;
}
}
}
}
}
cout << res << "\n";
return 0;
}
Compilation message
cubeword.cpp: In function 'bool isPalindrome(std::string&)':
cubeword.cpp:32:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (ll i = 0; i < str.size() / 2; i++) if (str[i] != str[str.size() - i - 1]) return false;
| ~~^~~~~~~~~~~~~~~~
cubeword.cpp: In function 'int main()':
cubeword.cpp:57:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (ll i = 0; i < characters.size(); i++) charShrink[characters[i]] = i;
| ~~^~~~~~~~~~~~~~~~~~~
cubeword.cpp:58:49: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (ll i = 0; i < n; i++) for (ll j = 0; j < words[i].size(); j++) words[i][j] = charShrink[words[i][j]];
| ~~^~~~~~~~~~~~~~~~~
cubeword.cpp:74:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for (ll j = 0; j < byLength[i].size(); j++)
| ~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
192 ms |
15848 KB |
Output is correct |
2 |
Correct |
183 ms |
15860 KB |
Output is correct |
3 |
Correct |
183 ms |
15864 KB |
Output is correct |
4 |
Correct |
181 ms |
15824 KB |
Output is correct |
5 |
Correct |
183 ms |
15844 KB |
Output is correct |
6 |
Correct |
177 ms |
15872 KB |
Output is correct |
7 |
Correct |
179 ms |
15848 KB |
Output is correct |
8 |
Correct |
179 ms |
15876 KB |
Output is correct |
9 |
Correct |
178 ms |
15840 KB |
Output is correct |
10 |
Correct |
177 ms |
15868 KB |
Output is correct |
11 |
Correct |
180 ms |
15864 KB |
Output is correct |
12 |
Correct |
177 ms |
15844 KB |
Output is correct |
13 |
Correct |
180 ms |
15812 KB |
Output is correct |
14 |
Correct |
182 ms |
15864 KB |
Output is correct |
15 |
Correct |
199 ms |
15860 KB |
Output is correct |
16 |
Correct |
187 ms |
15840 KB |
Output is correct |
17 |
Correct |
186 ms |
15868 KB |
Output is correct |
18 |
Correct |
186 ms |
15840 KB |
Output is correct |
19 |
Correct |
188 ms |
15840 KB |
Output is correct |
20 |
Correct |
177 ms |
15840 KB |
Output is correct |
21 |
Correct |
188 ms |
15844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
192 ms |
15848 KB |
Output is correct |
2 |
Correct |
183 ms |
15860 KB |
Output is correct |
3 |
Correct |
183 ms |
15864 KB |
Output is correct |
4 |
Correct |
181 ms |
15824 KB |
Output is correct |
5 |
Correct |
183 ms |
15844 KB |
Output is correct |
6 |
Correct |
177 ms |
15872 KB |
Output is correct |
7 |
Correct |
179 ms |
15848 KB |
Output is correct |
8 |
Correct |
179 ms |
15876 KB |
Output is correct |
9 |
Correct |
178 ms |
15840 KB |
Output is correct |
10 |
Correct |
177 ms |
15868 KB |
Output is correct |
11 |
Correct |
180 ms |
15864 KB |
Output is correct |
12 |
Correct |
177 ms |
15844 KB |
Output is correct |
13 |
Correct |
180 ms |
15812 KB |
Output is correct |
14 |
Correct |
182 ms |
15864 KB |
Output is correct |
15 |
Correct |
199 ms |
15860 KB |
Output is correct |
16 |
Correct |
187 ms |
15840 KB |
Output is correct |
17 |
Correct |
186 ms |
15868 KB |
Output is correct |
18 |
Correct |
186 ms |
15840 KB |
Output is correct |
19 |
Correct |
188 ms |
15840 KB |
Output is correct |
20 |
Correct |
177 ms |
15840 KB |
Output is correct |
21 |
Correct |
188 ms |
15844 KB |
Output is correct |
22 |
Correct |
187 ms |
16336 KB |
Output is correct |
23 |
Correct |
207 ms |
16296 KB |
Output is correct |
24 |
Correct |
189 ms |
16276 KB |
Output is correct |
25 |
Correct |
181 ms |
16288 KB |
Output is correct |
26 |
Correct |
182 ms |
16312 KB |
Output is correct |
27 |
Correct |
182 ms |
16292 KB |
Output is correct |
28 |
Correct |
181 ms |
16324 KB |
Output is correct |
29 |
Correct |
185 ms |
16320 KB |
Output is correct |
30 |
Correct |
182 ms |
16288 KB |
Output is correct |
31 |
Correct |
185 ms |
16308 KB |
Output is correct |
32 |
Correct |
180 ms |
16284 KB |
Output is correct |
33 |
Correct |
181 ms |
16316 KB |
Output is correct |
34 |
Correct |
182 ms |
16324 KB |
Output is correct |
35 |
Correct |
181 ms |
16324 KB |
Output is correct |
36 |
Correct |
185 ms |
16324 KB |
Output is correct |
37 |
Correct |
196 ms |
16312 KB |
Output is correct |
38 |
Correct |
184 ms |
16296 KB |
Output is correct |
39 |
Correct |
185 ms |
16316 KB |
Output is correct |
40 |
Correct |
188 ms |
16316 KB |
Output is correct |
41 |
Correct |
196 ms |
16300 KB |
Output is correct |
42 |
Correct |
185 ms |
16324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
192 ms |
15848 KB |
Output is correct |
2 |
Correct |
183 ms |
15860 KB |
Output is correct |
3 |
Correct |
183 ms |
15864 KB |
Output is correct |
4 |
Correct |
181 ms |
15824 KB |
Output is correct |
5 |
Correct |
183 ms |
15844 KB |
Output is correct |
6 |
Correct |
177 ms |
15872 KB |
Output is correct |
7 |
Correct |
179 ms |
15848 KB |
Output is correct |
8 |
Correct |
179 ms |
15876 KB |
Output is correct |
9 |
Correct |
178 ms |
15840 KB |
Output is correct |
10 |
Correct |
177 ms |
15868 KB |
Output is correct |
11 |
Correct |
180 ms |
15864 KB |
Output is correct |
12 |
Correct |
177 ms |
15844 KB |
Output is correct |
13 |
Correct |
180 ms |
15812 KB |
Output is correct |
14 |
Correct |
182 ms |
15864 KB |
Output is correct |
15 |
Correct |
199 ms |
15860 KB |
Output is correct |
16 |
Correct |
187 ms |
15840 KB |
Output is correct |
17 |
Correct |
186 ms |
15868 KB |
Output is correct |
18 |
Correct |
186 ms |
15840 KB |
Output is correct |
19 |
Correct |
188 ms |
15840 KB |
Output is correct |
20 |
Correct |
177 ms |
15840 KB |
Output is correct |
21 |
Correct |
188 ms |
15844 KB |
Output is correct |
22 |
Correct |
187 ms |
16336 KB |
Output is correct |
23 |
Correct |
207 ms |
16296 KB |
Output is correct |
24 |
Correct |
189 ms |
16276 KB |
Output is correct |
25 |
Correct |
181 ms |
16288 KB |
Output is correct |
26 |
Correct |
182 ms |
16312 KB |
Output is correct |
27 |
Correct |
182 ms |
16292 KB |
Output is correct |
28 |
Correct |
181 ms |
16324 KB |
Output is correct |
29 |
Correct |
185 ms |
16320 KB |
Output is correct |
30 |
Correct |
182 ms |
16288 KB |
Output is correct |
31 |
Correct |
185 ms |
16308 KB |
Output is correct |
32 |
Correct |
180 ms |
16284 KB |
Output is correct |
33 |
Correct |
181 ms |
16316 KB |
Output is correct |
34 |
Correct |
182 ms |
16324 KB |
Output is correct |
35 |
Correct |
181 ms |
16324 KB |
Output is correct |
36 |
Correct |
185 ms |
16324 KB |
Output is correct |
37 |
Correct |
196 ms |
16312 KB |
Output is correct |
38 |
Correct |
184 ms |
16296 KB |
Output is correct |
39 |
Correct |
185 ms |
16316 KB |
Output is correct |
40 |
Correct |
188 ms |
16316 KB |
Output is correct |
41 |
Correct |
196 ms |
16300 KB |
Output is correct |
42 |
Correct |
185 ms |
16324 KB |
Output is correct |
43 |
Correct |
185 ms |
16444 KB |
Output is correct |
44 |
Correct |
190 ms |
16452 KB |
Output is correct |
45 |
Correct |
187 ms |
16448 KB |
Output is correct |
46 |
Correct |
186 ms |
16440 KB |
Output is correct |
47 |
Correct |
189 ms |
16440 KB |
Output is correct |
48 |
Correct |
192 ms |
16472 KB |
Output is correct |
49 |
Correct |
186 ms |
16456 KB |
Output is correct |
50 |
Correct |
203 ms |
16592 KB |
Output is correct |
51 |
Correct |
181 ms |
16456 KB |
Output is correct |
52 |
Correct |
180 ms |
16432 KB |
Output is correct |
53 |
Correct |
181 ms |
16472 KB |
Output is correct |
54 |
Correct |
182 ms |
16508 KB |
Output is correct |
55 |
Correct |
182 ms |
16444 KB |
Output is correct |
56 |
Correct |
180 ms |
16452 KB |
Output is correct |
57 |
Correct |
188 ms |
16424 KB |
Output is correct |
58 |
Correct |
195 ms |
16452 KB |
Output is correct |
59 |
Correct |
184 ms |
16516 KB |
Output is correct |
60 |
Correct |
189 ms |
16448 KB |
Output is correct |
61 |
Correct |
181 ms |
16464 KB |
Output is correct |
62 |
Correct |
180 ms |
16432 KB |
Output is correct |
63 |
Correct |
182 ms |
16476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
192 ms |
15848 KB |
Output is correct |
2 |
Correct |
183 ms |
15860 KB |
Output is correct |
3 |
Correct |
183 ms |
15864 KB |
Output is correct |
4 |
Correct |
181 ms |
15824 KB |
Output is correct |
5 |
Correct |
183 ms |
15844 KB |
Output is correct |
6 |
Correct |
177 ms |
15872 KB |
Output is correct |
7 |
Correct |
179 ms |
15848 KB |
Output is correct |
8 |
Correct |
179 ms |
15876 KB |
Output is correct |
9 |
Correct |
178 ms |
15840 KB |
Output is correct |
10 |
Correct |
177 ms |
15868 KB |
Output is correct |
11 |
Correct |
180 ms |
15864 KB |
Output is correct |
12 |
Correct |
177 ms |
15844 KB |
Output is correct |
13 |
Correct |
180 ms |
15812 KB |
Output is correct |
14 |
Correct |
182 ms |
15864 KB |
Output is correct |
15 |
Correct |
199 ms |
15860 KB |
Output is correct |
16 |
Correct |
187 ms |
15840 KB |
Output is correct |
17 |
Correct |
186 ms |
15868 KB |
Output is correct |
18 |
Correct |
186 ms |
15840 KB |
Output is correct |
19 |
Correct |
188 ms |
15840 KB |
Output is correct |
20 |
Correct |
177 ms |
15840 KB |
Output is correct |
21 |
Correct |
188 ms |
15844 KB |
Output is correct |
22 |
Correct |
187 ms |
16336 KB |
Output is correct |
23 |
Correct |
207 ms |
16296 KB |
Output is correct |
24 |
Correct |
189 ms |
16276 KB |
Output is correct |
25 |
Correct |
181 ms |
16288 KB |
Output is correct |
26 |
Correct |
182 ms |
16312 KB |
Output is correct |
27 |
Correct |
182 ms |
16292 KB |
Output is correct |
28 |
Correct |
181 ms |
16324 KB |
Output is correct |
29 |
Correct |
185 ms |
16320 KB |
Output is correct |
30 |
Correct |
182 ms |
16288 KB |
Output is correct |
31 |
Correct |
185 ms |
16308 KB |
Output is correct |
32 |
Correct |
180 ms |
16284 KB |
Output is correct |
33 |
Correct |
181 ms |
16316 KB |
Output is correct |
34 |
Correct |
182 ms |
16324 KB |
Output is correct |
35 |
Correct |
181 ms |
16324 KB |
Output is correct |
36 |
Correct |
185 ms |
16324 KB |
Output is correct |
37 |
Correct |
196 ms |
16312 KB |
Output is correct |
38 |
Correct |
184 ms |
16296 KB |
Output is correct |
39 |
Correct |
185 ms |
16316 KB |
Output is correct |
40 |
Correct |
188 ms |
16316 KB |
Output is correct |
41 |
Correct |
196 ms |
16300 KB |
Output is correct |
42 |
Correct |
185 ms |
16324 KB |
Output is correct |
43 |
Correct |
185 ms |
16444 KB |
Output is correct |
44 |
Correct |
190 ms |
16452 KB |
Output is correct |
45 |
Correct |
187 ms |
16448 KB |
Output is correct |
46 |
Correct |
186 ms |
16440 KB |
Output is correct |
47 |
Correct |
189 ms |
16440 KB |
Output is correct |
48 |
Correct |
192 ms |
16472 KB |
Output is correct |
49 |
Correct |
186 ms |
16456 KB |
Output is correct |
50 |
Correct |
203 ms |
16592 KB |
Output is correct |
51 |
Correct |
181 ms |
16456 KB |
Output is correct |
52 |
Correct |
180 ms |
16432 KB |
Output is correct |
53 |
Correct |
181 ms |
16472 KB |
Output is correct |
54 |
Correct |
182 ms |
16508 KB |
Output is correct |
55 |
Correct |
182 ms |
16444 KB |
Output is correct |
56 |
Correct |
180 ms |
16452 KB |
Output is correct |
57 |
Correct |
188 ms |
16424 KB |
Output is correct |
58 |
Correct |
195 ms |
16452 KB |
Output is correct |
59 |
Correct |
184 ms |
16516 KB |
Output is correct |
60 |
Correct |
189 ms |
16448 KB |
Output is correct |
61 |
Correct |
181 ms |
16464 KB |
Output is correct |
62 |
Correct |
180 ms |
16432 KB |
Output is correct |
63 |
Correct |
182 ms |
16476 KB |
Output is correct |
64 |
Correct |
183 ms |
16592 KB |
Output is correct |
65 |
Correct |
191 ms |
17352 KB |
Output is correct |
66 |
Correct |
192 ms |
17332 KB |
Output is correct |
67 |
Correct |
191 ms |
17852 KB |
Output is correct |
68 |
Correct |
204 ms |
17332 KB |
Output is correct |
69 |
Correct |
194 ms |
17344 KB |
Output is correct |
70 |
Correct |
189 ms |
17440 KB |
Output is correct |
71 |
Correct |
188 ms |
17344 KB |
Output is correct |
72 |
Correct |
187 ms |
17340 KB |
Output is correct |
73 |
Correct |
195 ms |
17344 KB |
Output is correct |
74 |
Correct |
192 ms |
17372 KB |
Output is correct |
75 |
Correct |
191 ms |
17344 KB |
Output is correct |
76 |
Correct |
192 ms |
17344 KB |
Output is correct |
77 |
Correct |
188 ms |
17348 KB |
Output is correct |
78 |
Correct |
187 ms |
17340 KB |
Output is correct |
79 |
Correct |
195 ms |
17504 KB |
Output is correct |
80 |
Correct |
184 ms |
17372 KB |
Output is correct |
81 |
Correct |
184 ms |
17524 KB |
Output is correct |
82 |
Correct |
210 ms |
17536 KB |
Output is correct |
83 |
Correct |
198 ms |
17368 KB |
Output is correct |
84 |
Correct |
181 ms |
17348 KB |
Output is correct |