Submission #1277459

#TimeUsernameProblemLanguageResultExecution timeMemory
1277459not_amirCubeword (CEOI19_cubeword)C++20
0 / 100
1136 ms29928 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; constexpr int MAX = 62, MOD = 998'244'353; int ctoi(char c) { if ('0' <= c && c <= '9') return c - '0'; if ('a' <= c && c <= 'z') return 10 + c - 'a'; return 10 + 'z' - 'a' + 1 + c - 'A'; } ll H[11][MAX][MAX], cnt[11][MAX][MAX][MAX]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; map<string, bool> in; for (int i = 0; i < n; i++) { string s; cin >> s; if (in[s]) continue; string rs = s; reverse(s.begin(), s.end()); in[s] = in[rs] = true; int a = ctoi(s[0]), b = ctoi(s.back()); H[s.length()][a][b]++; if (s != rs) H[s.length()][b][a]++; } ll res = 0; for (int l = 3; l <= 10; l++) { for (int i = 0; i < MAX; i++) for (int j = 0; j < MAX; j++) for (int k = 0; k < MAX; k++) for (int w = 0; w < MAX; w++) (cnt[l][i][j][k] += 1ll * H[l][i][w] * H[l][j][w] * H[l][k][w] % MOD) %= MOD; for (int i = 0; i < MAX; i++) { for (int j = 0; j < MAX; j++) { for (int k = 0; k < MAX; k++) { for (int w = 0; w < MAX; w++) { ll prod = 1; // array<int, 4> ind = {i, j, k, w}; // for (int d1 = 0; d1 < 4; d1++) { // vector<int> v; // v.reserve(3); // for (int d2 = 0; d2 < 4; d2++) // if (d1 != d2) // v.push_back(ind[d2]); // prod = prod * cnt[l][v[0]][v[1]][v[2]] % MOD; // } prod = cnt[l][j][k][w] * cnt[l][i][k][w] % MOD * cnt[l][i][j][w] % MOD * cnt[l][i][j][k] % MOD; res = (res + prod) % MOD; } } } } } cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...