Submission #960810

# Submission time Handle Problem Language Result Execution time Memory
960810 2024-04-11T04:40:26 Z ALTAKEXE Cubeword (CEOI19_cubeword) C++17
0 / 100
48 ms 8168 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAX_ID = 62;
const int MIN_LEN = 3;
const int MAX_LEN = 10;
const int MOD = 998244353;
vector<string> s[MAX_LEN + 1];
unordered_map<char, int> id;
int m;
int coef[MAX_ID][MAX_ID], prod[MAX_ID][MAX_ID][MAX_ID];
 
int solve() {
    int ans = 0;
 
    for ( int a = 0; a < m; a++ ) {
        for ( int b = 0; b < m; b++ ) {
            for ( int c = 0; c < m; c++ ) {
                prod[a][b][c] = 0;
                for ( int i = 0; i < m; i++ )
                    prod[a][b][c] = (prod[a][b][c] + (long long)coef[a][i] * coef[b][i] % MOD * coef[c][i]) % MOD;
            }
        }
    }
 
 
    for ( int a = 0; a < m; a++ ) {
        for ( int b = 0; b < m; b++ ) {
            for ( int c = 0; c < m; c++ ) {
                for ( int d = 0; d < m; d++ )
                    ans = (ans + prod[a][b][c] * (long long)prod[a][b][d] % MOD * prod[a][c][d] % MOD * prod[b][c][d]) % MOD;
            }
        }
    }
 
    return ans;
}
 
int main() {
    cin.tie( NULL );
    ios_base::sync_with_stdio( false );
 
    int n;
 
    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        string t;
        cin >> t;
        s[t.size()].push_back( t );
        string w = t;
        reverse( w.begin(), w.end() );
        if ( w != t )
            s[t.size()].push_back( w );
        for ( int i = 0; i < t.size(); i++ )
            id[t[i]] = 1;
    }
 
    m = 0;
    for ( auto p: id )
        id[p.first] = m++;
 
    int ans = 0;
    for ( int l = MIN_LEN; l <= MAX_LEN; l++ ) {
        if ( s[l].size() == 0 )
            continue;
 
        for ( int i = 0; i < m; i++ ) {
            for ( int j = 0; j < m; j++ )
                coef[i][j] = 0;
        }
        sort( s[l].begin(), s[l].end() );
        for ( int i = 0; i < s[l].size(); i++ ) {
            if ( i == 0 || s[l][i] != s[l][i - 1])
                coef[id[s[l][i][0]]][id[s[l][i].back()]]++;
        }
 
        ans += solve();
    }
 
    cout << ans;
 
    return 0;
}

Compilation message

cubeword.cpp: In function 'int main()':
cubeword.cpp:55:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for ( int i = 0; i < t.size(); i++ )
      |                          ~~^~~~~~~~~~
cubeword.cpp:73:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for ( int i = 0; i < s[l].size(); i++ ) {
      |                          ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 8168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 8168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 8168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 8168 KB Output isn't correct
2 Halted 0 ms 0 KB -