# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
904789 | 2024-01-12T08:29:00 Z | andrei_iorgulescu | Cubeword (CEOI19_cubeword) | C++14 | 678 ms | 18848 KB |
#include <bits/stdc++.h> using namespace std; const int S = 62; const int modulo = 998244353; vector<string>cuv[15]; int cst[S][S]; int cost[S][S][S]; int toint(char c) { if (c >= 'a' and c <= 'z') return c - 'a'; else if (c >= 'A' and c <= 'Z') return 26 + c - 'A'; else return 52 + c - '0'; } bool palint(string s) { for (int i = 1; i < s.size() - 1; i++) if (s[i] != s[s.size() - 1 - i]) return false; return true; } string inv(string s) { reverse(s.begin(),s.end()); return s; } map<string,bool>mp; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; for (int i = 1; i <= n; i++) { string s; cin >> s; cuv[s.size()].push_back(s); } int ans = 0; for (int l = 3; l <= 10; l++) { for (int i = 0; i < S; i++) for (int j = 0; j < S; j++) cst[i][j] = 0; for (int i = 0; i < S; i++) for (int j = 0; j < S; j++) for (int k = 0; k < S; k++) cost[i][j][k] = 0; for (auto it : cuv[l]) { if (mp[inv(it)] == true) continue; mp[it] = true; cst[toint(it[0])][toint(it[l - 1])]++; if (it[0] != it[l - 1]) cst[toint(it[l - 1])][toint(it[0])]++; else if (palint(it) == false) cst[toint(it[0])][toint(it[l - 1])]++; } for (int i = 0; i < S; i++) { for (int j = 0; j < S; j++) { for (int k = 0; k < S; k++) { for (int q = 0; q < S; q++) cost[i][j][k] = (0ll + cost[i][j][k] + 1ll * cst[i][q] * cst[j][q] * cst[k][q]) % modulo; } } } for (int A = 0; A < S; A++) { for (int B = 0; B < S; B++) { for (int C = 0; C < S; C++) { for (int D = 0; D < S; D++) { if (cost[A][B][C] != 0 and cost[A][B][D] != 0 and cost[A][C][D] != 0 and cost[B][C][D] != 0) ans += 1ll * cost[A][B][C] * cost[A][B][D] % modulo * cost[A][C][D] % modulo * cost[B][C][D] % modulo; } } } } } cout << ans % modulo; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 678 ms | 18848 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 678 ms | 18848 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 678 ms | 18848 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 678 ms | 18848 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |