#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cnt[6][6][11];
ll ans = 0;
const ll mod = 998244353;
vector<int> k[8];
void solve(int dep, vector<int> v, int t, ll now)
{
if(dep == 8)
{
ans = (ans + now)%mod;
return;
}
else
{
for(int i=0;i<6;i++)
{
v.push_back(i);
ll tmp = now;
for(int j : k[dep])
{
tmp *= cnt[i][v[j]][t];
tmp %= mod;
}
solve(dep+1, v, t, tmp);
v.pop_back();
}
}
}
int main()
{
int n; cin >> n;
for(int i=1;i<=n;i++)
{
string s; cin >> s;
int t = s.size();
int a = s[0] - 'a';
int b = s[t-1] - 'a';
bool flag = true;
for(int i=0;i<t;i++)
{
if(s[i] != s[t-i-1]) flag = false;
}
if(a != b) { cnt[a][b][t]++; cnt[b][a][t]++; }
else if(flag) cnt[a][a][t]++;
else cnt[a][a][t] += 2;
}
k[1].push_back(0);
k[2].push_back(0);
k[3].push_back(1); k[3].push_back(2);
k[4].push_back(0);
k[5].push_back(1); k[5].push_back(4);
k[6].push_back(2); k[6].push_back(4);
k[7].push_back(3); k[7].push_back(5); k[7].push_back(6);
for(int t=3;t<=10;t++)
{
vector<int> emp;
solve(0, emp, t, 1);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1057 ms |
1136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1057 ms |
1136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1057 ms |
1136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1057 ms |
1136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |