#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];
vector<int> V;
map<string, int> M;
void solve(int dep, 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, t, tmp);
V.pop_back();
}
}
}
int main()
{
int n; cin >> n;
for(int i=1;i<=n;i++)
{
string s; cin >> s;
string p = s;
reverse(p.begin(), p.end());
if(M[p]) continue;
M[s] = 1;
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++)
{
solve(0, t, 1);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
523 ms |
14884 KB |
Output is correct |
2 |
Correct |
516 ms |
15688 KB |
Output is correct |
3 |
Correct |
608 ms |
15608 KB |
Output is correct |
4 |
Correct |
515 ms |
15684 KB |
Output is correct |
5 |
Correct |
527 ms |
15624 KB |
Output is correct |
6 |
Correct |
516 ms |
15620 KB |
Output is correct |
7 |
Correct |
532 ms |
15744 KB |
Output is correct |
8 |
Correct |
520 ms |
15628 KB |
Output is correct |
9 |
Correct |
516 ms |
15552 KB |
Output is correct |
10 |
Correct |
506 ms |
15620 KB |
Output is correct |
11 |
Correct |
534 ms |
15708 KB |
Output is correct |
12 |
Correct |
531 ms |
15604 KB |
Output is correct |
13 |
Correct |
539 ms |
15624 KB |
Output is correct |
14 |
Correct |
506 ms |
15684 KB |
Output is correct |
15 |
Correct |
516 ms |
15628 KB |
Output is correct |
16 |
Correct |
501 ms |
15632 KB |
Output is correct |
17 |
Correct |
498 ms |
15620 KB |
Output is correct |
18 |
Correct |
508 ms |
15768 KB |
Output is correct |
19 |
Correct |
509 ms |
15608 KB |
Output is correct |
20 |
Correct |
498 ms |
15620 KB |
Output is correct |
21 |
Correct |
527 ms |
15632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
523 ms |
14884 KB |
Output is correct |
2 |
Correct |
516 ms |
15688 KB |
Output is correct |
3 |
Correct |
608 ms |
15608 KB |
Output is correct |
4 |
Correct |
515 ms |
15684 KB |
Output is correct |
5 |
Correct |
527 ms |
15624 KB |
Output is correct |
6 |
Correct |
516 ms |
15620 KB |
Output is correct |
7 |
Correct |
532 ms |
15744 KB |
Output is correct |
8 |
Correct |
520 ms |
15628 KB |
Output is correct |
9 |
Correct |
516 ms |
15552 KB |
Output is correct |
10 |
Correct |
506 ms |
15620 KB |
Output is correct |
11 |
Correct |
534 ms |
15708 KB |
Output is correct |
12 |
Correct |
531 ms |
15604 KB |
Output is correct |
13 |
Correct |
539 ms |
15624 KB |
Output is correct |
14 |
Correct |
506 ms |
15684 KB |
Output is correct |
15 |
Correct |
516 ms |
15628 KB |
Output is correct |
16 |
Correct |
501 ms |
15632 KB |
Output is correct |
17 |
Correct |
498 ms |
15620 KB |
Output is correct |
18 |
Correct |
508 ms |
15768 KB |
Output is correct |
19 |
Correct |
509 ms |
15608 KB |
Output is correct |
20 |
Correct |
498 ms |
15620 KB |
Output is correct |
21 |
Correct |
527 ms |
15632 KB |
Output is correct |
22 |
Runtime error |
9 ms |
2632 KB |
Execution killed with signal 11 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
523 ms |
14884 KB |
Output is correct |
2 |
Correct |
516 ms |
15688 KB |
Output is correct |
3 |
Correct |
608 ms |
15608 KB |
Output is correct |
4 |
Correct |
515 ms |
15684 KB |
Output is correct |
5 |
Correct |
527 ms |
15624 KB |
Output is correct |
6 |
Correct |
516 ms |
15620 KB |
Output is correct |
7 |
Correct |
532 ms |
15744 KB |
Output is correct |
8 |
Correct |
520 ms |
15628 KB |
Output is correct |
9 |
Correct |
516 ms |
15552 KB |
Output is correct |
10 |
Correct |
506 ms |
15620 KB |
Output is correct |
11 |
Correct |
534 ms |
15708 KB |
Output is correct |
12 |
Correct |
531 ms |
15604 KB |
Output is correct |
13 |
Correct |
539 ms |
15624 KB |
Output is correct |
14 |
Correct |
506 ms |
15684 KB |
Output is correct |
15 |
Correct |
516 ms |
15628 KB |
Output is correct |
16 |
Correct |
501 ms |
15632 KB |
Output is correct |
17 |
Correct |
498 ms |
15620 KB |
Output is correct |
18 |
Correct |
508 ms |
15768 KB |
Output is correct |
19 |
Correct |
509 ms |
15608 KB |
Output is correct |
20 |
Correct |
498 ms |
15620 KB |
Output is correct |
21 |
Correct |
527 ms |
15632 KB |
Output is correct |
22 |
Runtime error |
9 ms |
2632 KB |
Execution killed with signal 11 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
523 ms |
14884 KB |
Output is correct |
2 |
Correct |
516 ms |
15688 KB |
Output is correct |
3 |
Correct |
608 ms |
15608 KB |
Output is correct |
4 |
Correct |
515 ms |
15684 KB |
Output is correct |
5 |
Correct |
527 ms |
15624 KB |
Output is correct |
6 |
Correct |
516 ms |
15620 KB |
Output is correct |
7 |
Correct |
532 ms |
15744 KB |
Output is correct |
8 |
Correct |
520 ms |
15628 KB |
Output is correct |
9 |
Correct |
516 ms |
15552 KB |
Output is correct |
10 |
Correct |
506 ms |
15620 KB |
Output is correct |
11 |
Correct |
534 ms |
15708 KB |
Output is correct |
12 |
Correct |
531 ms |
15604 KB |
Output is correct |
13 |
Correct |
539 ms |
15624 KB |
Output is correct |
14 |
Correct |
506 ms |
15684 KB |
Output is correct |
15 |
Correct |
516 ms |
15628 KB |
Output is correct |
16 |
Correct |
501 ms |
15632 KB |
Output is correct |
17 |
Correct |
498 ms |
15620 KB |
Output is correct |
18 |
Correct |
508 ms |
15768 KB |
Output is correct |
19 |
Correct |
509 ms |
15608 KB |
Output is correct |
20 |
Correct |
498 ms |
15620 KB |
Output is correct |
21 |
Correct |
527 ms |
15632 KB |
Output is correct |
22 |
Runtime error |
9 ms |
2632 KB |
Execution killed with signal 11 |
23 |
Halted |
0 ms |
0 KB |
- |