/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD1 (1000000000+7)
#define MOD (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;
int n, S = 65;
ll dp[100][100], d[70][70][70];
vector<string> s[15];
bool is_palindrome(string &a){
bool ok = 1;
int x = a.length();
for(int i = 0; i < x / 2; ++i) ok &= (a[i] == a[x - i - 1]);
return ok;
}
int comb(int a, int b, int c, int d){
if(a==b && b==c && c==d) return 1;
if(a==b && b==c && c!=d) return 4;
if(a==b && b!=c && c==d) return 6;
if(a!=b && b==c && c==d) return 4;
if(a==b && b!=c && c!=d) return 12;
if(a!=b && b==c && c!=d) return 12;
if(a!=b && b!=c && c==d) return 12;
return 24;
}
void solve(){
cin >> n;
for(int i = 0; i < n; ++i){
string a; cin >> a;
for(char &c: a){
if(c >= '0' && c <= '9'){
c = 'z' + 26 + (c - '0') + 1;
}
else if(!(c >= 'a' && c <= 'z')){
c = 'z' + (c - 'A') + 1;
}
}
s[a.length()].pb(a);
}
ll ans = 0;
for(int i = 1; i < 15; ++i){
if(s[i].empty()) continue;
for(int j = 0; j < S; ++j) for(int k = 0; k < S; ++k) dp[j][k] = 0;
map<string, bool> used;
for(auto a: s[i]){
if(used[a]) continue;
if(is_palindrome(a)){
dp[a[0] - 'a'][a[0] - 'a']++;
}else{
dp[a[0] - 'a'][a.back() - 'a']++;
dp[a.back() - 'a'][a[0] - 'a']++;
}
reverse(all(a));
used[a] = 1;
}
for(int a = 0; a < S; ++a){
for(int b = a; b < S; ++b){
for(int c = b; c < S; ++c){
d[a][b][c] = 0;
for(int l = 0; l < S; ++l){
(d[a][b][c] += (dp[a][l] * dp[b][l] % MOD) * dp[c][l]) %= MOD;
}
}
}
}
for(int a = 0; a < S; ++a){
for(int b = a; b < S; ++b){
for(int c = b; c < S; ++c){
for(int e = c; e < S; ++e){
ll p = (d[a][b][c] * d[a][b][e] % MOD) * (d[a][c][e] * d[b][c][e] % MOD) % MOD;
(ans += p * comb(a, b, c, e)) %= MOD;
}
}
}
}
}
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
}
return 0;
}
Compilation message
cubeword.cpp: In function 'int main()':
cubeword.cpp:104:16: warning: unused variable 'aa' [-Wunused-variable]
104 | int T = 1, aa;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
223 ms |
7884 KB |
Output is correct |
2 |
Correct |
231 ms |
7956 KB |
Output is correct |
3 |
Correct |
232 ms |
7980 KB |
Output is correct |
4 |
Correct |
227 ms |
8220 KB |
Output is correct |
5 |
Correct |
230 ms |
7892 KB |
Output is correct |
6 |
Correct |
232 ms |
7904 KB |
Output is correct |
7 |
Correct |
232 ms |
8092 KB |
Output is correct |
8 |
Correct |
232 ms |
8000 KB |
Output is correct |
9 |
Correct |
244 ms |
7968 KB |
Output is correct |
10 |
Correct |
228 ms |
8012 KB |
Output is correct |
11 |
Correct |
237 ms |
7976 KB |
Output is correct |
12 |
Correct |
246 ms |
7972 KB |
Output is correct |
13 |
Correct |
226 ms |
7908 KB |
Output is correct |
14 |
Correct |
244 ms |
7992 KB |
Output is correct |
15 |
Correct |
230 ms |
7976 KB |
Output is correct |
16 |
Correct |
227 ms |
7976 KB |
Output is correct |
17 |
Correct |
246 ms |
8208 KB |
Output is correct |
18 |
Correct |
235 ms |
7888 KB |
Output is correct |
19 |
Correct |
231 ms |
7964 KB |
Output is correct |
20 |
Correct |
229 ms |
8000 KB |
Output is correct |
21 |
Correct |
221 ms |
7944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
223 ms |
7884 KB |
Output is correct |
2 |
Correct |
231 ms |
7956 KB |
Output is correct |
3 |
Correct |
232 ms |
7980 KB |
Output is correct |
4 |
Correct |
227 ms |
8220 KB |
Output is correct |
5 |
Correct |
230 ms |
7892 KB |
Output is correct |
6 |
Correct |
232 ms |
7904 KB |
Output is correct |
7 |
Correct |
232 ms |
8092 KB |
Output is correct |
8 |
Correct |
232 ms |
8000 KB |
Output is correct |
9 |
Correct |
244 ms |
7968 KB |
Output is correct |
10 |
Correct |
228 ms |
8012 KB |
Output is correct |
11 |
Correct |
237 ms |
7976 KB |
Output is correct |
12 |
Correct |
246 ms |
7972 KB |
Output is correct |
13 |
Correct |
226 ms |
7908 KB |
Output is correct |
14 |
Correct |
244 ms |
7992 KB |
Output is correct |
15 |
Correct |
230 ms |
7976 KB |
Output is correct |
16 |
Correct |
227 ms |
7976 KB |
Output is correct |
17 |
Correct |
246 ms |
8208 KB |
Output is correct |
18 |
Correct |
235 ms |
7888 KB |
Output is correct |
19 |
Correct |
231 ms |
7964 KB |
Output is correct |
20 |
Correct |
229 ms |
8000 KB |
Output is correct |
21 |
Correct |
221 ms |
7944 KB |
Output is correct |
22 |
Correct |
256 ms |
7172 KB |
Output is correct |
23 |
Correct |
227 ms |
7172 KB |
Output is correct |
24 |
Correct |
225 ms |
7156 KB |
Output is correct |
25 |
Correct |
234 ms |
7144 KB |
Output is correct |
26 |
Correct |
230 ms |
7164 KB |
Output is correct |
27 |
Correct |
219 ms |
7148 KB |
Output is correct |
28 |
Correct |
230 ms |
7164 KB |
Output is correct |
29 |
Correct |
225 ms |
7164 KB |
Output is correct |
30 |
Correct |
224 ms |
7108 KB |
Output is correct |
31 |
Correct |
223 ms |
7116 KB |
Output is correct |
32 |
Correct |
247 ms |
7148 KB |
Output is correct |
33 |
Correct |
219 ms |
7196 KB |
Output is correct |
34 |
Correct |
237 ms |
7176 KB |
Output is correct |
35 |
Correct |
231 ms |
7176 KB |
Output is correct |
36 |
Correct |
231 ms |
7160 KB |
Output is correct |
37 |
Correct |
244 ms |
7068 KB |
Output is correct |
38 |
Correct |
230 ms |
7232 KB |
Output is correct |
39 |
Correct |
247 ms |
7080 KB |
Output is correct |
40 |
Correct |
226 ms |
7144 KB |
Output is correct |
41 |
Correct |
234 ms |
7176 KB |
Output is correct |
42 |
Correct |
222 ms |
7232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
223 ms |
7884 KB |
Output is correct |
2 |
Correct |
231 ms |
7956 KB |
Output is correct |
3 |
Correct |
232 ms |
7980 KB |
Output is correct |
4 |
Correct |
227 ms |
8220 KB |
Output is correct |
5 |
Correct |
230 ms |
7892 KB |
Output is correct |
6 |
Correct |
232 ms |
7904 KB |
Output is correct |
7 |
Correct |
232 ms |
8092 KB |
Output is correct |
8 |
Correct |
232 ms |
8000 KB |
Output is correct |
9 |
Correct |
244 ms |
7968 KB |
Output is correct |
10 |
Correct |
228 ms |
8012 KB |
Output is correct |
11 |
Correct |
237 ms |
7976 KB |
Output is correct |
12 |
Correct |
246 ms |
7972 KB |
Output is correct |
13 |
Correct |
226 ms |
7908 KB |
Output is correct |
14 |
Correct |
244 ms |
7992 KB |
Output is correct |
15 |
Correct |
230 ms |
7976 KB |
Output is correct |
16 |
Correct |
227 ms |
7976 KB |
Output is correct |
17 |
Correct |
246 ms |
8208 KB |
Output is correct |
18 |
Correct |
235 ms |
7888 KB |
Output is correct |
19 |
Correct |
231 ms |
7964 KB |
Output is correct |
20 |
Correct |
229 ms |
8000 KB |
Output is correct |
21 |
Correct |
221 ms |
7944 KB |
Output is correct |
22 |
Correct |
256 ms |
7172 KB |
Output is correct |
23 |
Correct |
227 ms |
7172 KB |
Output is correct |
24 |
Correct |
225 ms |
7156 KB |
Output is correct |
25 |
Correct |
234 ms |
7144 KB |
Output is correct |
26 |
Correct |
230 ms |
7164 KB |
Output is correct |
27 |
Correct |
219 ms |
7148 KB |
Output is correct |
28 |
Correct |
230 ms |
7164 KB |
Output is correct |
29 |
Correct |
225 ms |
7164 KB |
Output is correct |
30 |
Correct |
224 ms |
7108 KB |
Output is correct |
31 |
Correct |
223 ms |
7116 KB |
Output is correct |
32 |
Correct |
247 ms |
7148 KB |
Output is correct |
33 |
Correct |
219 ms |
7196 KB |
Output is correct |
34 |
Correct |
237 ms |
7176 KB |
Output is correct |
35 |
Correct |
231 ms |
7176 KB |
Output is correct |
36 |
Correct |
231 ms |
7160 KB |
Output is correct |
37 |
Correct |
244 ms |
7068 KB |
Output is correct |
38 |
Correct |
230 ms |
7232 KB |
Output is correct |
39 |
Correct |
247 ms |
7080 KB |
Output is correct |
40 |
Correct |
226 ms |
7144 KB |
Output is correct |
41 |
Correct |
234 ms |
7176 KB |
Output is correct |
42 |
Correct |
222 ms |
7232 KB |
Output is correct |
43 |
Incorrect |
234 ms |
7160 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
223 ms |
7884 KB |
Output is correct |
2 |
Correct |
231 ms |
7956 KB |
Output is correct |
3 |
Correct |
232 ms |
7980 KB |
Output is correct |
4 |
Correct |
227 ms |
8220 KB |
Output is correct |
5 |
Correct |
230 ms |
7892 KB |
Output is correct |
6 |
Correct |
232 ms |
7904 KB |
Output is correct |
7 |
Correct |
232 ms |
8092 KB |
Output is correct |
8 |
Correct |
232 ms |
8000 KB |
Output is correct |
9 |
Correct |
244 ms |
7968 KB |
Output is correct |
10 |
Correct |
228 ms |
8012 KB |
Output is correct |
11 |
Correct |
237 ms |
7976 KB |
Output is correct |
12 |
Correct |
246 ms |
7972 KB |
Output is correct |
13 |
Correct |
226 ms |
7908 KB |
Output is correct |
14 |
Correct |
244 ms |
7992 KB |
Output is correct |
15 |
Correct |
230 ms |
7976 KB |
Output is correct |
16 |
Correct |
227 ms |
7976 KB |
Output is correct |
17 |
Correct |
246 ms |
8208 KB |
Output is correct |
18 |
Correct |
235 ms |
7888 KB |
Output is correct |
19 |
Correct |
231 ms |
7964 KB |
Output is correct |
20 |
Correct |
229 ms |
8000 KB |
Output is correct |
21 |
Correct |
221 ms |
7944 KB |
Output is correct |
22 |
Correct |
256 ms |
7172 KB |
Output is correct |
23 |
Correct |
227 ms |
7172 KB |
Output is correct |
24 |
Correct |
225 ms |
7156 KB |
Output is correct |
25 |
Correct |
234 ms |
7144 KB |
Output is correct |
26 |
Correct |
230 ms |
7164 KB |
Output is correct |
27 |
Correct |
219 ms |
7148 KB |
Output is correct |
28 |
Correct |
230 ms |
7164 KB |
Output is correct |
29 |
Correct |
225 ms |
7164 KB |
Output is correct |
30 |
Correct |
224 ms |
7108 KB |
Output is correct |
31 |
Correct |
223 ms |
7116 KB |
Output is correct |
32 |
Correct |
247 ms |
7148 KB |
Output is correct |
33 |
Correct |
219 ms |
7196 KB |
Output is correct |
34 |
Correct |
237 ms |
7176 KB |
Output is correct |
35 |
Correct |
231 ms |
7176 KB |
Output is correct |
36 |
Correct |
231 ms |
7160 KB |
Output is correct |
37 |
Correct |
244 ms |
7068 KB |
Output is correct |
38 |
Correct |
230 ms |
7232 KB |
Output is correct |
39 |
Correct |
247 ms |
7080 KB |
Output is correct |
40 |
Correct |
226 ms |
7144 KB |
Output is correct |
41 |
Correct |
234 ms |
7176 KB |
Output is correct |
42 |
Correct |
222 ms |
7232 KB |
Output is correct |
43 |
Incorrect |
234 ms |
7160 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |