This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 32, mod = 998244353; // subtasks 1-2
int ans;
int edge[11][maxn][maxn];
int value_triad[11][maxn][maxn][maxn];
int id(char c) { if(c <= 'p') return c-'a'; return c-'A'; } // subtaks 1-2
set<string> mark;
void add(int& a, int b) { a += b; if(a >= mod) a -= mod; }
int D[11][maxn][maxn][maxn];
int main() {
int n; cin >> n;
string s;
for(int i = 0; i < n; i++) {
cin >> s;
for(int rep = 0; rep < 2; rep++, reverse(s.begin(), s.end())) if(!mark.count(s)) {
edge[s.size()][id(s[0])][id(s.back())]++;
mark.insert(s);
}
}
for(int sz = 3; sz <= 10; sz++)
for(int a = 0; a < maxn; a++) for(int b = 0; b < maxn; b++) for(int c = 0; c < maxn; c++)
for(int x = 0; x < maxn; x++)
add(D[sz][a][b][c], 1ll * edge[sz][x][a] * edge[sz][x][b] % mod * edge[sz][x][c] % mod);
for(int sz = 3; sz <= 10; sz++) {
for(int a = 0; a < maxn; a++) for(int b = 0; b < maxn; b++) for(int c = 0; c < maxn; c++) for(int d = 0; d < maxn; d++)
add(ans, 1ll * D[sz][a][b][c] * D[sz][a][b][d] % mod * D[sz][a][c][d] % mod * D[sz][b][c][d] % mod);
}
printf("%d\n", ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |