# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
556658 | fatemetmhr | Cubeword (CEOI19_cubeword) | C++17 | 1192 ms | 25680 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.
// ~~ Be name khoda ~~ //
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
const int al = 65;
const int szz = 10;
const int mod = 998244353;
const int maxn5 = 1e5 + 10;
set <string> av;
int id[maxn5];
int have[al][al][al][szz];
int cnt[szz][al][al];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n; cin >> n;
for(int i = 0; i < n; i++){
string s; cin >> s;
av.insert(s);
reverse(all(s));
av.insert(s);
}
int ind = 0;
for(int i = 0; i < 26; i++){
id[i + 'a'] = ind++;
id[i + 'A'] = ind++;
if(i < 10)
id[i + '0'] = ind++;
}
for(auto it = av.begin(); it != av.end(); it++){
string s = (*it);
cnt[s.size() - 3][id[s[0]]][id[s[s.size() - 1]]]++;
}
for(int i = 0; i < ind; i++) for(int j = 0; j < ind; j++)
for(int k = 0; k < ind; k++) for(int sz = 0; sz <= 8; sz++) for(int z = 0; z < ind; z++)
have[i][j][k][sz] = (have[i][j][k][sz] + (ll(cnt[sz][i][z]) * cnt[sz][j][z] % mod) * cnt[sz][k][z]) % mod;
ll ans = 0;
for(int i = 0; i < ind; i++) for(int j = 0; j < ind; j++)
for(int k = 0; k < ind; k++) for(int z = 0; z < ind; z++) for(int sz = 0; sz <= 8; sz++)
ans = (ans + ((ll(have[i][j][k][sz]) * have[i][j][z][sz] % mod) * have[i][k][z][sz] % mod) * have[j][k][z][sz]) % mod;
cout << ans << endl;
}
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... |