#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) 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 = 0; j < c; j++)
{
for (ll k = 0; 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 = 0; corner2 < c; corner2++)
{
for (ll corner3 = 0; corner3 < c; corner3++)
{
for (ll corner4 = 0; 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) % 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++)
| ~~^~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
13736 KB |
Output is correct |
2 |
Correct |
95 ms |
14636 KB |
Output is correct |
3 |
Correct |
98 ms |
14636 KB |
Output is correct |
4 |
Correct |
98 ms |
14624 KB |
Output is correct |
5 |
Correct |
98 ms |
14820 KB |
Output is correct |
6 |
Correct |
96 ms |
14784 KB |
Output is correct |
7 |
Correct |
96 ms |
14796 KB |
Output is correct |
8 |
Correct |
94 ms |
14768 KB |
Output is correct |
9 |
Correct |
111 ms |
14828 KB |
Output is correct |
10 |
Correct |
97 ms |
14624 KB |
Output is correct |
11 |
Correct |
140 ms |
14760 KB |
Output is correct |
12 |
Correct |
99 ms |
14576 KB |
Output is correct |
13 |
Correct |
103 ms |
14712 KB |
Output is correct |
14 |
Correct |
101 ms |
14744 KB |
Output is correct |
15 |
Correct |
101 ms |
14720 KB |
Output is correct |
16 |
Correct |
103 ms |
14748 KB |
Output is correct |
17 |
Correct |
111 ms |
14624 KB |
Output is correct |
18 |
Correct |
103 ms |
14744 KB |
Output is correct |
19 |
Correct |
133 ms |
14744 KB |
Output is correct |
20 |
Correct |
99 ms |
14748 KB |
Output is correct |
21 |
Correct |
97 ms |
14748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
13736 KB |
Output is correct |
2 |
Correct |
95 ms |
14636 KB |
Output is correct |
3 |
Correct |
98 ms |
14636 KB |
Output is correct |
4 |
Correct |
98 ms |
14624 KB |
Output is correct |
5 |
Correct |
98 ms |
14820 KB |
Output is correct |
6 |
Correct |
96 ms |
14784 KB |
Output is correct |
7 |
Correct |
96 ms |
14796 KB |
Output is correct |
8 |
Correct |
94 ms |
14768 KB |
Output is correct |
9 |
Correct |
111 ms |
14828 KB |
Output is correct |
10 |
Correct |
97 ms |
14624 KB |
Output is correct |
11 |
Correct |
140 ms |
14760 KB |
Output is correct |
12 |
Correct |
99 ms |
14576 KB |
Output is correct |
13 |
Correct |
103 ms |
14712 KB |
Output is correct |
14 |
Correct |
101 ms |
14744 KB |
Output is correct |
15 |
Correct |
101 ms |
14720 KB |
Output is correct |
16 |
Correct |
103 ms |
14748 KB |
Output is correct |
17 |
Correct |
111 ms |
14624 KB |
Output is correct |
18 |
Correct |
103 ms |
14744 KB |
Output is correct |
19 |
Correct |
133 ms |
14744 KB |
Output is correct |
20 |
Correct |
99 ms |
14748 KB |
Output is correct |
21 |
Correct |
97 ms |
14748 KB |
Output is correct |
22 |
Correct |
102 ms |
14940 KB |
Output is correct |
23 |
Correct |
101 ms |
15136 KB |
Output is correct |
24 |
Correct |
102 ms |
15108 KB |
Output is correct |
25 |
Correct |
96 ms |
15132 KB |
Output is correct |
26 |
Correct |
101 ms |
15136 KB |
Output is correct |
27 |
Correct |
98 ms |
15008 KB |
Output is correct |
28 |
Correct |
97 ms |
15132 KB |
Output is correct |
29 |
Correct |
102 ms |
15088 KB |
Output is correct |
30 |
Correct |
98 ms |
15020 KB |
Output is correct |
31 |
Correct |
99 ms |
15080 KB |
Output is correct |
32 |
Correct |
97 ms |
15064 KB |
Output is correct |
33 |
Correct |
97 ms |
14944 KB |
Output is correct |
34 |
Correct |
97 ms |
15012 KB |
Output is correct |
35 |
Correct |
100 ms |
15008 KB |
Output is correct |
36 |
Correct |
98 ms |
15048 KB |
Output is correct |
37 |
Correct |
97 ms |
15132 KB |
Output is correct |
38 |
Correct |
97 ms |
15136 KB |
Output is correct |
39 |
Correct |
104 ms |
15132 KB |
Output is correct |
40 |
Correct |
99 ms |
15068 KB |
Output is correct |
41 |
Correct |
105 ms |
15132 KB |
Output is correct |
42 |
Correct |
101 ms |
15176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
13736 KB |
Output is correct |
2 |
Correct |
95 ms |
14636 KB |
Output is correct |
3 |
Correct |
98 ms |
14636 KB |
Output is correct |
4 |
Correct |
98 ms |
14624 KB |
Output is correct |
5 |
Correct |
98 ms |
14820 KB |
Output is correct |
6 |
Correct |
96 ms |
14784 KB |
Output is correct |
7 |
Correct |
96 ms |
14796 KB |
Output is correct |
8 |
Correct |
94 ms |
14768 KB |
Output is correct |
9 |
Correct |
111 ms |
14828 KB |
Output is correct |
10 |
Correct |
97 ms |
14624 KB |
Output is correct |
11 |
Correct |
140 ms |
14760 KB |
Output is correct |
12 |
Correct |
99 ms |
14576 KB |
Output is correct |
13 |
Correct |
103 ms |
14712 KB |
Output is correct |
14 |
Correct |
101 ms |
14744 KB |
Output is correct |
15 |
Correct |
101 ms |
14720 KB |
Output is correct |
16 |
Correct |
103 ms |
14748 KB |
Output is correct |
17 |
Correct |
111 ms |
14624 KB |
Output is correct |
18 |
Correct |
103 ms |
14744 KB |
Output is correct |
19 |
Correct |
133 ms |
14744 KB |
Output is correct |
20 |
Correct |
99 ms |
14748 KB |
Output is correct |
21 |
Correct |
97 ms |
14748 KB |
Output is correct |
22 |
Correct |
102 ms |
14940 KB |
Output is correct |
23 |
Correct |
101 ms |
15136 KB |
Output is correct |
24 |
Correct |
102 ms |
15108 KB |
Output is correct |
25 |
Correct |
96 ms |
15132 KB |
Output is correct |
26 |
Correct |
101 ms |
15136 KB |
Output is correct |
27 |
Correct |
98 ms |
15008 KB |
Output is correct |
28 |
Correct |
97 ms |
15132 KB |
Output is correct |
29 |
Correct |
102 ms |
15088 KB |
Output is correct |
30 |
Correct |
98 ms |
15020 KB |
Output is correct |
31 |
Correct |
99 ms |
15080 KB |
Output is correct |
32 |
Correct |
97 ms |
15064 KB |
Output is correct |
33 |
Correct |
97 ms |
14944 KB |
Output is correct |
34 |
Correct |
97 ms |
15012 KB |
Output is correct |
35 |
Correct |
100 ms |
15008 KB |
Output is correct |
36 |
Correct |
98 ms |
15048 KB |
Output is correct |
37 |
Correct |
97 ms |
15132 KB |
Output is correct |
38 |
Correct |
97 ms |
15136 KB |
Output is correct |
39 |
Correct |
104 ms |
15132 KB |
Output is correct |
40 |
Correct |
99 ms |
15068 KB |
Output is correct |
41 |
Correct |
105 ms |
15132 KB |
Output is correct |
42 |
Correct |
101 ms |
15176 KB |
Output is correct |
43 |
Incorrect |
97 ms |
12068 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
13736 KB |
Output is correct |
2 |
Correct |
95 ms |
14636 KB |
Output is correct |
3 |
Correct |
98 ms |
14636 KB |
Output is correct |
4 |
Correct |
98 ms |
14624 KB |
Output is correct |
5 |
Correct |
98 ms |
14820 KB |
Output is correct |
6 |
Correct |
96 ms |
14784 KB |
Output is correct |
7 |
Correct |
96 ms |
14796 KB |
Output is correct |
8 |
Correct |
94 ms |
14768 KB |
Output is correct |
9 |
Correct |
111 ms |
14828 KB |
Output is correct |
10 |
Correct |
97 ms |
14624 KB |
Output is correct |
11 |
Correct |
140 ms |
14760 KB |
Output is correct |
12 |
Correct |
99 ms |
14576 KB |
Output is correct |
13 |
Correct |
103 ms |
14712 KB |
Output is correct |
14 |
Correct |
101 ms |
14744 KB |
Output is correct |
15 |
Correct |
101 ms |
14720 KB |
Output is correct |
16 |
Correct |
103 ms |
14748 KB |
Output is correct |
17 |
Correct |
111 ms |
14624 KB |
Output is correct |
18 |
Correct |
103 ms |
14744 KB |
Output is correct |
19 |
Correct |
133 ms |
14744 KB |
Output is correct |
20 |
Correct |
99 ms |
14748 KB |
Output is correct |
21 |
Correct |
97 ms |
14748 KB |
Output is correct |
22 |
Correct |
102 ms |
14940 KB |
Output is correct |
23 |
Correct |
101 ms |
15136 KB |
Output is correct |
24 |
Correct |
102 ms |
15108 KB |
Output is correct |
25 |
Correct |
96 ms |
15132 KB |
Output is correct |
26 |
Correct |
101 ms |
15136 KB |
Output is correct |
27 |
Correct |
98 ms |
15008 KB |
Output is correct |
28 |
Correct |
97 ms |
15132 KB |
Output is correct |
29 |
Correct |
102 ms |
15088 KB |
Output is correct |
30 |
Correct |
98 ms |
15020 KB |
Output is correct |
31 |
Correct |
99 ms |
15080 KB |
Output is correct |
32 |
Correct |
97 ms |
15064 KB |
Output is correct |
33 |
Correct |
97 ms |
14944 KB |
Output is correct |
34 |
Correct |
97 ms |
15012 KB |
Output is correct |
35 |
Correct |
100 ms |
15008 KB |
Output is correct |
36 |
Correct |
98 ms |
15048 KB |
Output is correct |
37 |
Correct |
97 ms |
15132 KB |
Output is correct |
38 |
Correct |
97 ms |
15136 KB |
Output is correct |
39 |
Correct |
104 ms |
15132 KB |
Output is correct |
40 |
Correct |
99 ms |
15068 KB |
Output is correct |
41 |
Correct |
105 ms |
15132 KB |
Output is correct |
42 |
Correct |
101 ms |
15176 KB |
Output is correct |
43 |
Incorrect |
97 ms |
12068 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |