#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)
const long long mod = 998244353;
const int MAX_VAL = 32;
int N; string S[1 << 18];
char c[10009];
int cnt[62][62];
long long ret[62][62][62];
int getc(char d) {
if ('a' <= d && d <= 'z') return (d - 'a');
if ('A' <= d && d <= 'Z') return (d - 'A') + 26;
return (d - '0') + 52;
}
long long getcnt(int v1, int v2) {
if (v1 != v2) return cnt[v1][v2] + cnt[v2][v1];
return cnt[v1][v2];
}
long long solve(int pos) {
for (int i = 0; i < 62 * 62; i++) cnt[i / 62][i % 62] = 0;
vector<string> vec;
for (int i = 1; i <= N; i++) {
if (S[i].size() != pos) continue;
string T = S[i]; reverse(T.begin(), T.end());
vec.push_back(S[i]);
vec.push_back(T);
}
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
for (string i : vec) {
int c1 = getc(i[0]), c2 = getc(i[i.size() - 1]);
if (c1 > c2) swap(c1, c2);
cnt[c1][c2] += 1;
}
for (int i = 0; i < MAX_VAL; i++) {
for (int j = i; j < MAX_VAL; j++) {
for (int k = j; k < MAX_VAL; k++) {
ret[i][j][k] = 0;
for (int l = 0; l < MAX_VAL; l++) {
ret[i][j][k] += getcnt(i, l) * getcnt(j, l) * getcnt(k, l);
ret[i][j][k] %= mod;
}
}
}
}
long long val = 0;
for (int i = 0; i < MAX_VAL; i++) {
for (int j = 0; j < MAX_VAL; j++) {
for (int k = 0; k < MAX_VAL; k++) {
for (int l = 0; l < MAX_VAL; l++) {
int c[4] = { i, j, k, l };
sort(c, c + 4);
int A = c[0], B = c[1], C = c[2], D = c[3];
val += (ret[A][B][C] * ret[A][B][D] % mod) * (ret[A][C][D] * ret[B][C][D] % mod);
val %= mod;
}
}
}
}
return val;
}
int main() {
cin >> N;
for (int i = 1; i <= N; i++) {
for (int j = 0; j < 11; j++) c[j] = 0;
scanf("%s", &c);
for (int j = 0; j < 11; j++) { if (c[j] == 0) break; S[i] += c[j]; }
}
long long ans = 0;
for (int i = 3; i <= 10; i++) {
ans += solve(i);
ans %= mod;
}
cout << ans << endl;
return 0;
}
Compilation message
cubeword.cpp:6:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning (disable: 4996)
cubeword.cpp: In function 'long long int solve(int)':
cubeword.cpp:33:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (S[i].size() != pos) continue;
~~~~~~~~~~~~^~~~~~
cubeword.cpp: In function 'int main()':
cubeword.cpp:80:17: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[10009]' [-Wformat=]
scanf("%s", &c);
~~^
cubeword.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", &c);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
347 ms |
12452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
347 ms |
12452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
347 ms |
12452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
347 ms |
12452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |