Submission #953579

# Submission time Handle Problem Language Result Execution time Memory
953579 2024-03-26T09:22:05 Z mircea_007 Cubeword (CEOI19_cubeword) C++17
0 / 100
1100 ms 17092 KB
#include <iostream>
#include <string>
#include <unordered_set>
#include <algorithm>

const int MOD = 998244353;
using ll = long long;

struct ZP {
  int x;

  ZP( int x = 0 ): x(x % MOD) {}
  ZP( ll x ): x(x % MOD) {}
  explicit operator int() { return x; }

  ZP operator *= ( const ZP& that ) { return *this = ZP( x * (ll)that.x ); }
  ZP operator += ( const ZP& that ) {
    x += that.x;
    if( x >= MOD )
      x -= MOD;

    return *this;
  }

  ZP operator * ( const ZP& that ) const { return ZP( *this ) *= that; }
  ZP operator + ( const ZP& that ) const { return ZP( *this ) += that; }
};

const int SIGMA = 62; // defapt 62 dar speram sa se alinieze mai bine asa
const int MINLEN = 3;
const int MAXLEN = 10;

int char_idx[128];

ZP freq[MAXLEN + 1][SIGMA][SIGMA];
ZP lfreq[SIGMA][SIGMA];
ZP 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 <= 'z' ; ch++ )
      char_idx[ch] = idx++;
    for( int ch = 'A' ; ch <= 'Z' ; 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()]] += ZP(1);

  ZP 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] += lfreq[a][mij] * lfreq[b][mij] * lfreq[c][mij];
        }
    }

    // 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 += triangle[a][b][c] * triangle[b][c][d] * triangle[a][c][d] * triangle[a][b][d];
  }

  printf( "%d\n", int(ret) );
  
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1094 ms 17092 KB Output is correct
2 Correct 1098 ms 17092 KB Output is correct
3 Execution timed out 1123 ms 17088 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1094 ms 17092 KB Output is correct
2 Correct 1098 ms 17092 KB Output is correct
3 Execution timed out 1123 ms 17088 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1094 ms 17092 KB Output is correct
2 Correct 1098 ms 17092 KB Output is correct
3 Execution timed out 1123 ms 17088 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1094 ms 17092 KB Output is correct
2 Correct 1098 ms 17092 KB Output is correct
3 Execution timed out 1123 ms 17088 KB Time limit exceeded
4 Halted 0 ms 0 KB -