# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
779938 |
2023-07-12T03:31:49 Z |
mmk |
Cubeword (CEOI19_cubeword) |
C++14 |
|
1100 ms |
16752 KB |
#include<bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
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' + 36 + 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]; mult %= MOD;
mult *= cont[b][end]; mult %= MOD;
mult *= cont[c][end]; mult %= MOD;
freq[a][b][c] += mult;
ans %= 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
cubeword.cpp: In function 'long long int getId(char)':
cubeword.cpp:18:1: warning: control reaches end of non-void function [-Wreturn-type]
18 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1156 ms |
16752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1156 ms |
16752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1156 ms |
16752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1156 ms |
16752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |