# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
321234 | phathnv | Cubeword (CEOI19_cubeword) | C++11 | 277 ms | 13272 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
vector <string> words;
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;
words.push_back(s);
reverse(s.begin(), s.end());
words.push_back(s);
}
sort(words.begin(), words.end());
words.resize(unique(words.begin(), words.end()) - words.begin());
for(string &s : words){
int fr = ind(s.front());
int bk = ind(s.back());
adj[s.size() - 3][fr][bk]++;
}
}
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 (stderr)
# | 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... |