#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
const int MOD = 998244353LL;
const int MAX_N = 40LL;
int nbP[MAX_N][MAX_N];
int RES = 0;
vector<pii> cube_edges = {
{0, 1},
{1, 2},
{2, 3},
{3, 0},
{4, 5},
{5, 6},
{6, 7},
{7, 4},
{0, 4},
{1, 5},
{2, 6},
{3, 7},
};
bool is_palindrome(string s){
bool ok = true;
for(int i = 0; i<(s.size()+1)/2; i++){
ok &= (s[i] == s[s.size()-i-1]);
}
return ok;
}
int mexp(int a, int b){
int res = 1;
vector<int>pows(1, a);
for(int i= 1; i<35; i++){
pows.push_back((pows.back()*pows.back())%MOD);
}
for(int i = 0; i<35; i++){
if(0!=((1LL<<i)&b)){
res = (res * pows[i])%MOD;
}
}
return res;
}
int modinv(int a){
int b= mexp(a, MOD-2);
assert((a*b)%MOD == 1);
return b;
}
vector<pair<int, vector<int>>> iterate_all(int nbSteps, int maxC){
vector<int> cur = vector<int>(nbSteps, 0);
vector<pair<int, vector<int>>> res;
bool ok = true;
for(int first_v = 0; first_v <maxC; first_v++){
cur =vector<int>(nbSteps, 0);
cur[0] = first_v;
ok =true;
while(ok){
cur.back()++;
for(int i = nbSteps-1; i>1; i--){
if(cur[i]>first_v){
cur[i-1]++;
cur[i] = 0;
}
}
if(cur[1] >first_v){
ok = false;
cur[1] = 0;
}
else{
int nb_same = 0;
for(auto e: cur){
if(e == first_v){
nb_same++;
}
}
res.push_back({nbSteps * modinv(nb_same), cur});
}
}
}
return res;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin>>N;
vector<vector<string>> words(11);
for(int i = 0; i<N; i++){
string s;
cin>>s;
words[s.size()].push_back(s);
}
vector<pair<int, vector<int>>> colorings= iterate_all(8, 6);
for(int len = 3; len<=10; len++){
fill(&nbP[0][0], &nbP[MAX_N][0], 0);
for(auto e: words[len]){
if(e.size() == len){
int a= e[0]-'a';
int b= e.back()-'a';
if(is_palindrome(e)){
nbP[a][b]++;
}
else{
nbP[a][b]++;
nbP[b][a]++;
}
}
}
for(auto list: colorings){
int nb_cur = 1;
for(auto edge: cube_edges){
nb_cur = (nb_cur * nbP[list.second[edge.first]][list.second[edge.second]])%MOD;
}
nb_cur = (nb_cur * list.first)%MOD;
RES = (RES + nb_cur)%MOD;
}
}
cout<<RES<<endl;
}
Compilation message
cubeword.cpp: In function 'bool is_palindrome(std::string)':
cubeword.cpp:30:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i = 0; i<(s.size()+1)/2; i++){
| ~^~~~~~~~~~~~~~~
cubeword.cpp: In function 'int main()':
cubeword.cpp:117:25: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
117 | if(e.size() == len){
| ~~~~~~~~~^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
287 ms |
46556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
287 ms |
46556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
287 ms |
46556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
287 ms |
46556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |