This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#include <iostream>
#include <string>
#include <unordered_set>
#include <algorithm>
#define MOD 998244353
using ll = long long;
#define SIGMA 32
const int MINLEN = 3;
const int MAXLEN = 10;
int char_idx[128];
int freq[MAXLEN + 1][SIGMA][SIGMA];
int lfreq[SIGMA][SIGMA];
int triangle[SIGMA][SIGMA][SIGMA];
int main() {
int n;
std::cin >> n;
// hash map
std::unordered_set<std::string> words;
for( int i = 0 ; i < n ; i++ ){
std::string w;
std::cin >> w;
words.insert( w );
std::reverse( w.begin(), w.end() );
words.insert( w );
}
{
int idx = 0;
for( int ch = 'a' ; ch <= 'p' ; ch++ )
char_idx[ch] = idx++;
for( int ch = 'A' ; ch <= 'P' ; ch++ )
char_idx[ch] = idx++;
//for( int ch = '0' ; ch <= '9' ; ch++ )
// char_idx[ch] = idx++;
}
for( std::string w : words )
freq[(int)w.size()][char_idx[(int)w.front()]][char_idx[(int)w.back()]]++;
int ret = 0;
for( int len = MINLEN ; len <= MAXLEN ; len++ ){
for( int a = 0 ; a < SIGMA ; a++ )
for( int b = 0 ; b < SIGMA ; b++ )
lfreq[a][b] = freq[len][a][b];
for( int a = 0 ; a < SIGMA ; a++ ){
for( int b = 0 ; b < SIGMA ; b++ )
for( int c = 0 ; c < SIGMA ; c++ ){
triangle[a][b][c] = 0;
for( int mij = 0 ; mij < SIGMA ; mij++ )
triangle[a][b][c] = (triangle[a][b][c] + (lfreq[a][mij] * (ll)lfreq[b][mij]) % MOD * (ll)lfreq[c][mij]) % MOD;
}
}
// fixam 4 colturi neadiacente (oricare doua unite printr-o diagonala de latura)
for( int a = 0 ; a < SIGMA ; a++ )
for( int b = 0 ; b < SIGMA ; b++ )
for( int c = 0 ; c < SIGMA ; c++ )
for( int d = 0 ; d < SIGMA ; d++ )
ret = (ret + (triangle[a][b][c] * (ll)triangle[b][c][d]) % MOD * (ll)triangle[a][c][d] % MOD * (ll)triangle[a][b][d]) % MOD;
}
printf( "%d\n", ret );
return 0;
}
# | 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... |