# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
779925 | mmk | Cubeword (CEOI19_cubeword) | C++14 | 872 ms | 16588 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 int long long
const int ALP = 62;
const int MOD = 998244353;
const int MAXN = 1e5 + 10;
using namespace std;
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 *= freq[a][c][d];
add *= freq[b][c][d];
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 (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... |