# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
779928 | 2023-07-12T03:16:32 Z | mmk | Cubeword (CEOI19_cubeword) | C++14 | 1100 ms | 15568 KB |
#include<bits/stdc++.h> #define int long long const int ALP = 62; const int MOD = 998244353; using namespace std; unordered_set<string> words[15]; int getId(char c) { if(c <= '9') return c - '0'; if(c <= 'Z') return c - 'A' + '9' - '0' + 1; if(c <= 'z') return c - 'a' + 'Z' - 'A' + 1 + '9' - '0' + 1; } int calc(int sz) { if(words[sz].size() == 0) return 0; int ans = 0; int freq[ALP][ALP][ALP] = {0}; int cont[ALP][ALP] = {0}; for(auto cur : words[sz]) { int beg = getId(cur[0]); int end = getId(cur.back()); cont[beg][end]++; } for(int a = 0; a < ALP; a++) { for(int b = 0; b < ALP; b++) { for(int c = 0; c < ALP; c++) { for(int end = 0; end < ALP; end++) { int mult = 1; mult *= cont[a][end] * cont[b][end] * cont[c][end]; mult %= MOD; freq[a][b][c] += mult; freq[a][b][c] %= MOD; } } } } for(int a = 0; a < ALP; a++) { for(int b = 0; b < ALP; b++) { for(int c = 0; c < ALP; c++) { for(int d = 0; d < ALP; d++) { int add = 1; add *= freq[a][b][c]; add %= MOD; add *= freq[a][c][d]; add %= MOD; add *= freq[b][c][d]; add %= MOD; add *= freq[a][b][d]; add %= MOD; ans += add; ans %= MOD; } } } } return ans; } int32_t main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; for(int i = 0; i < n; i++) { string aux; cin >> aux; string rev = aux; reverse(rev.begin(),rev.end()); words[aux.size()].insert(aux); words[aux.size()].insert(rev); } int resp = 0; for(int i = 3; i <= 10; i++) { resp += calc(i); resp %= MOD; } cout << resp; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1126 ms | 15568 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1126 ms | 15568 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1126 ms | 15568 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1126 ms | 15568 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |