# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
321232 | 2020-11-11T15:57:37 Z | phathnv | Cubeword (CEOI19_cubeword) | C++11 | 157 ms | 6756 KB |
#include <bits/stdc++.h> #define mp make_pair #define X first #define Y second #define taskname "Cubeword" using namespace std; typedef long long ll; typedef pair <int, int> ii; const int L = 8; const int M = 62; const int MOD = 998244353; int n, adj[L][M][M], cnt[L][M][M][M]; int ind(char ch){ if ('a' <= ch && ch <= 'z') return ch - 'a'; if ('A' <= ch && ch <= 'Z') return ch - 'A' + 26; return ch - '0' + 52; } void readInput(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1; i <= n; i++){ string s; cin >> s; int fr = ind(s.front()); int bk = ind(s.back()); int len = s.size(); if (fr != bk){ adj[len - 3][fr][bk]++; adj[len - 3][bk][fr]++; } else { string tmp = s; reverse(tmp.begin(), tmp.end()); adj[len - 3][fr][bk] += 2 - (tmp == s); } } } void add(int &x, const int &y){ x += y; x -= (x >= MOD) * MOD; } int cntWays(int a, int b, int c, int d){ if (a == b && b == c && c == d) return 1; if ((a == b && b == c) || (b == c && c == d)) return 4; if (a == b && c == d) return 6; if (a == b || b == c || c == d) return 12; return 24; } void solve(){ int res = 0; for(int len = 0; len < L; len++) for(int r = 0; r < M; r++) for(int a = 0; a < M; a++) for(int b = a; b < M; b++) for(int c = b; c < M; c++){ add(cnt[len][a][b][c], (ll) adj[len][r][a] * adj[len][r][b] * adj[len][r][c] % MOD); } for(int len = 0; len < L; len++) for(int a = 0; a < M; a++) for(int b = a; b < M; b++) for(int c = b; c < M; c++) for(int d = c; d < M; d++){ int val = (ll) cnt[len][a][b][c] * cnt[len][a][b][d] % MOD * cnt[len][a][c][d] % MOD * cnt[len][b][c][d] % MOD; add(res, (ll) val * cntWays(a, b, c, d) % MOD); } cout << res; } int main(){ if (fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } readInput(); solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 157 ms | 6756 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 157 ms | 6756 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 157 ms | 6756 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 157 ms | 6756 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |