#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define abc 35
#define mod 998244353
lli n,a,b,res,MAX;
lli dp[abc][abc][abc], palabras[12][abc][abc];
lli cas[abc][abc];
string st,rev;
map<string, lli> mapa;
lli convierte(char car) {
lli x;
x = car;
if (x > 96) x -= 96;
else {
x -= 65;
x += 17;
}
return x;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
rep (i,1,n) {
cin >> st;
rev = st;
reverse(st.begin(),st.end());
if (st.size() > MAX) MAX = st.size();
if (mapa.find(st) != mapa.end() && mapa.find(rev) != mapa.end()) continue;
mapa[st] = 1;
mapa[rev] = 1;
a = convierte(st[0]);
b = convierte(st[st.size()-1]);
if (a == b) {
palabras[st.size()][a][a]++;
if (st != rev) palabras[st.size()][a][a]++;
}
else {
palabras[st.size()][a][b]++;
palabras[st.size()][b][a]++;
}
}
rep (tam,3,MAX) {
rep(i,1,abc)
rep(j,i,abc) cas[i][j] = 0;
rep(i,1,abc) {
rep(j,i,abc) {
rep(k,j,abc) {
dp[i][j][k] = 0;
rep (num,1,abc) {
a = palabras[tam][i][num] * palabras[tam][j][num] * palabras[tam][k][num];
a %= mod;
dp[i][j][k] += a;
dp[i][j][k] %= mod;
}
//duda de repetidos
cas[i][j] += dp[i][j][k];
cas[i][j] %= mod;
if (i == j && i == k) continue;
if (j == k) {cas[j][k] += dp[i][j][k]; cas[j][k] %= mod;}
else if (i == j || i == k) {cas[i][k] += dp[i][j][k]; cas[i][k] %= mod;}
else {
cas[j][k] += dp[i][j][k]; cas[j][k] %= mod;
cas[i][k] += dp[i][j][k]; cas[i][k] %= mod;
}
}
}
}
rep(i,1,abc) {
rep(j,i,abc) {
rep(k,j,abc) {
a = cas[i][j] * cas[i][k];
a %= mod;
a *= cas[j][k];
a %= mod;
a *= dp[i][j][k];
a %= mod;
res += a;
res %= mod;
}
}
}
}
cout << res;
}
Compilation message
cubeword.cpp: In function 'int main()':
cubeword.cpp:41:23: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
41 | if (st.size() > MAX) MAX = st.size();
| ~~~~~~~~~~^~~~~
cubeword.cpp:71:49: warning: iteration 34 invokes undefined behavior [-Waggressive-loop-optimizations]
71 | a = palabras[tam][i][num] * palabras[tam][j][num] * palabras[tam][k][num];
| ~~~~~~~~~~~~~~~~~~~~^
cubeword.cpp:5:39: note: within this loop
5 | #define rep(i,a,b) for(int i = (a); i <= (b); i++)
| ^
cubeword.cpp:70:21: note: in expansion of macro 'rep'
70 | rep (num,1,abc) {
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
193 ms |
30660 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
193 ms |
30660 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
193 ms |
30660 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
193 ms |
30660 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |