답안 #953602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
953602 2024-03-26T10:07:59 Z mircea_007 Cubeword (CEOI19_cubeword) C++17
100 / 100
235 ms 17504 KB
#pragma GCC optimize("O3,unroll-loops")

#include <iostream>
#include <string>
#include <unordered_set>
#include <algorithm>

#define 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; }
};


#define SIGMA 62
const int MINLEN = 3;
const int MAXLEN = 10;

int char_idx[128];

int 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 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 = a ; b < SIGMA ; b++ )
        for( int c = b ; 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++ ){
      int coefa = 24;
      int streaka = 1;

      for( int b = a ; b < SIGMA ; b++ ){
        int streakb = 1 + (b == a) * streaka;
        int coefb = coefa / streakb;
        
        for( int c = b ; c < SIGMA ; c++ ){
          int streakc = 1 + (c == b) * streakb;
          int coefc = coefb / streakc;
          
          for( int d = c ; d < SIGMA ; d++ ){
            int streakd = 1 + (d == c) * streakc;
            int coefd = coefc / streakd;

            ret += ZP(coefd) * triangle[a][b][c] * triangle[b][c][d] * triangle[a][c][d] * triangle[a][b][d];
          }
        }
      }
    }
  }

  printf( "%d\n", int(ret) );
  
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 17088 KB Output is correct
2 Correct 195 ms 17088 KB Output is correct
3 Correct 187 ms 17092 KB Output is correct
4 Correct 186 ms 17100 KB Output is correct
5 Correct 192 ms 17024 KB Output is correct
6 Correct 191 ms 17156 KB Output is correct
7 Correct 197 ms 17096 KB Output is correct
8 Correct 193 ms 17124 KB Output is correct
9 Correct 203 ms 16960 KB Output is correct
10 Correct 191 ms 16972 KB Output is correct
11 Correct 204 ms 17128 KB Output is correct
12 Correct 191 ms 17092 KB Output is correct
13 Correct 187 ms 17164 KB Output is correct
14 Correct 189 ms 17052 KB Output is correct
15 Correct 190 ms 17092 KB Output is correct
16 Correct 191 ms 17156 KB Output is correct
17 Correct 191 ms 17080 KB Output is correct
18 Correct 190 ms 17092 KB Output is correct
19 Correct 200 ms 17092 KB Output is correct
20 Correct 195 ms 17088 KB Output is correct
21 Correct 194 ms 17096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 17088 KB Output is correct
2 Correct 195 ms 17088 KB Output is correct
3 Correct 187 ms 17092 KB Output is correct
4 Correct 186 ms 17100 KB Output is correct
5 Correct 192 ms 17024 KB Output is correct
6 Correct 191 ms 17156 KB Output is correct
7 Correct 197 ms 17096 KB Output is correct
8 Correct 193 ms 17124 KB Output is correct
9 Correct 203 ms 16960 KB Output is correct
10 Correct 191 ms 16972 KB Output is correct
11 Correct 204 ms 17128 KB Output is correct
12 Correct 191 ms 17092 KB Output is correct
13 Correct 187 ms 17164 KB Output is correct
14 Correct 189 ms 17052 KB Output is correct
15 Correct 190 ms 17092 KB Output is correct
16 Correct 191 ms 17156 KB Output is correct
17 Correct 191 ms 17080 KB Output is correct
18 Correct 190 ms 17092 KB Output is correct
19 Correct 200 ms 17092 KB Output is correct
20 Correct 195 ms 17088 KB Output is correct
21 Correct 194 ms 17096 KB Output is correct
22 Correct 210 ms 17048 KB Output is correct
23 Correct 195 ms 17024 KB Output is correct
24 Correct 198 ms 17080 KB Output is correct
25 Correct 185 ms 17068 KB Output is correct
26 Correct 196 ms 17064 KB Output is correct
27 Correct 197 ms 16952 KB Output is correct
28 Correct 191 ms 17024 KB Output is correct
29 Correct 219 ms 17120 KB Output is correct
30 Correct 186 ms 17068 KB Output is correct
31 Correct 188 ms 17068 KB Output is correct
32 Correct 193 ms 17060 KB Output is correct
33 Correct 195 ms 17024 KB Output is correct
34 Correct 187 ms 17032 KB Output is correct
35 Correct 196 ms 17024 KB Output is correct
36 Correct 192 ms 17084 KB Output is correct
37 Correct 203 ms 17076 KB Output is correct
38 Correct 202 ms 17316 KB Output is correct
39 Correct 187 ms 17024 KB Output is correct
40 Correct 193 ms 17068 KB Output is correct
41 Correct 235 ms 17136 KB Output is correct
42 Correct 189 ms 17016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 17088 KB Output is correct
2 Correct 195 ms 17088 KB Output is correct
3 Correct 187 ms 17092 KB Output is correct
4 Correct 186 ms 17100 KB Output is correct
5 Correct 192 ms 17024 KB Output is correct
6 Correct 191 ms 17156 KB Output is correct
7 Correct 197 ms 17096 KB Output is correct
8 Correct 193 ms 17124 KB Output is correct
9 Correct 203 ms 16960 KB Output is correct
10 Correct 191 ms 16972 KB Output is correct
11 Correct 204 ms 17128 KB Output is correct
12 Correct 191 ms 17092 KB Output is correct
13 Correct 187 ms 17164 KB Output is correct
14 Correct 189 ms 17052 KB Output is correct
15 Correct 190 ms 17092 KB Output is correct
16 Correct 191 ms 17156 KB Output is correct
17 Correct 191 ms 17080 KB Output is correct
18 Correct 190 ms 17092 KB Output is correct
19 Correct 200 ms 17092 KB Output is correct
20 Correct 195 ms 17088 KB Output is correct
21 Correct 194 ms 17096 KB Output is correct
22 Correct 210 ms 17048 KB Output is correct
23 Correct 195 ms 17024 KB Output is correct
24 Correct 198 ms 17080 KB Output is correct
25 Correct 185 ms 17068 KB Output is correct
26 Correct 196 ms 17064 KB Output is correct
27 Correct 197 ms 16952 KB Output is correct
28 Correct 191 ms 17024 KB Output is correct
29 Correct 219 ms 17120 KB Output is correct
30 Correct 186 ms 17068 KB Output is correct
31 Correct 188 ms 17068 KB Output is correct
32 Correct 193 ms 17060 KB Output is correct
33 Correct 195 ms 17024 KB Output is correct
34 Correct 187 ms 17032 KB Output is correct
35 Correct 196 ms 17024 KB Output is correct
36 Correct 192 ms 17084 KB Output is correct
37 Correct 203 ms 17076 KB Output is correct
38 Correct 202 ms 17316 KB Output is correct
39 Correct 187 ms 17024 KB Output is correct
40 Correct 193 ms 17068 KB Output is correct
41 Correct 235 ms 17136 KB Output is correct
42 Correct 189 ms 17016 KB Output is correct
43 Correct 193 ms 17276 KB Output is correct
44 Correct 211 ms 17272 KB Output is correct
45 Correct 210 ms 17020 KB Output is correct
46 Correct 210 ms 17224 KB Output is correct
47 Correct 190 ms 17020 KB Output is correct
48 Correct 203 ms 17020 KB Output is correct
49 Correct 190 ms 17260 KB Output is correct
50 Correct 212 ms 17020 KB Output is correct
51 Correct 202 ms 17020 KB Output is correct
52 Correct 195 ms 17020 KB Output is correct
53 Correct 205 ms 17020 KB Output is correct
54 Correct 209 ms 17268 KB Output is correct
55 Correct 197 ms 17020 KB Output is correct
56 Correct 191 ms 17180 KB Output is correct
57 Correct 188 ms 17024 KB Output is correct
58 Correct 191 ms 17168 KB Output is correct
59 Correct 191 ms 17016 KB Output is correct
60 Correct 206 ms 17252 KB Output is correct
61 Correct 195 ms 17244 KB Output is correct
62 Correct 211 ms 17016 KB Output is correct
63 Correct 182 ms 17132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 17088 KB Output is correct
2 Correct 195 ms 17088 KB Output is correct
3 Correct 187 ms 17092 KB Output is correct
4 Correct 186 ms 17100 KB Output is correct
5 Correct 192 ms 17024 KB Output is correct
6 Correct 191 ms 17156 KB Output is correct
7 Correct 197 ms 17096 KB Output is correct
8 Correct 193 ms 17124 KB Output is correct
9 Correct 203 ms 16960 KB Output is correct
10 Correct 191 ms 16972 KB Output is correct
11 Correct 204 ms 17128 KB Output is correct
12 Correct 191 ms 17092 KB Output is correct
13 Correct 187 ms 17164 KB Output is correct
14 Correct 189 ms 17052 KB Output is correct
15 Correct 190 ms 17092 KB Output is correct
16 Correct 191 ms 17156 KB Output is correct
17 Correct 191 ms 17080 KB Output is correct
18 Correct 190 ms 17092 KB Output is correct
19 Correct 200 ms 17092 KB Output is correct
20 Correct 195 ms 17088 KB Output is correct
21 Correct 194 ms 17096 KB Output is correct
22 Correct 210 ms 17048 KB Output is correct
23 Correct 195 ms 17024 KB Output is correct
24 Correct 198 ms 17080 KB Output is correct
25 Correct 185 ms 17068 KB Output is correct
26 Correct 196 ms 17064 KB Output is correct
27 Correct 197 ms 16952 KB Output is correct
28 Correct 191 ms 17024 KB Output is correct
29 Correct 219 ms 17120 KB Output is correct
30 Correct 186 ms 17068 KB Output is correct
31 Correct 188 ms 17068 KB Output is correct
32 Correct 193 ms 17060 KB Output is correct
33 Correct 195 ms 17024 KB Output is correct
34 Correct 187 ms 17032 KB Output is correct
35 Correct 196 ms 17024 KB Output is correct
36 Correct 192 ms 17084 KB Output is correct
37 Correct 203 ms 17076 KB Output is correct
38 Correct 202 ms 17316 KB Output is correct
39 Correct 187 ms 17024 KB Output is correct
40 Correct 193 ms 17068 KB Output is correct
41 Correct 235 ms 17136 KB Output is correct
42 Correct 189 ms 17016 KB Output is correct
43 Correct 193 ms 17276 KB Output is correct
44 Correct 211 ms 17272 KB Output is correct
45 Correct 210 ms 17020 KB Output is correct
46 Correct 210 ms 17224 KB Output is correct
47 Correct 190 ms 17020 KB Output is correct
48 Correct 203 ms 17020 KB Output is correct
49 Correct 190 ms 17260 KB Output is correct
50 Correct 212 ms 17020 KB Output is correct
51 Correct 202 ms 17020 KB Output is correct
52 Correct 195 ms 17020 KB Output is correct
53 Correct 205 ms 17020 KB Output is correct
54 Correct 209 ms 17268 KB Output is correct
55 Correct 197 ms 17020 KB Output is correct
56 Correct 191 ms 17180 KB Output is correct
57 Correct 188 ms 17024 KB Output is correct
58 Correct 191 ms 17168 KB Output is correct
59 Correct 191 ms 17016 KB Output is correct
60 Correct 206 ms 17252 KB Output is correct
61 Correct 195 ms 17244 KB Output is correct
62 Correct 211 ms 17016 KB Output is correct
63 Correct 182 ms 17132 KB Output is correct
64 Correct 185 ms 17308 KB Output is correct
65 Correct 191 ms 17276 KB Output is correct
66 Correct 194 ms 17456 KB Output is correct
67 Correct 219 ms 17452 KB Output is correct
68 Correct 187 ms 17456 KB Output is correct
69 Correct 182 ms 17272 KB Output is correct
70 Correct 203 ms 17452 KB Output is correct
71 Correct 188 ms 17276 KB Output is correct
72 Correct 188 ms 17460 KB Output is correct
73 Correct 208 ms 17452 KB Output is correct
74 Correct 201 ms 17448 KB Output is correct
75 Correct 191 ms 17452 KB Output is correct
76 Correct 201 ms 17448 KB Output is correct
77 Correct 190 ms 17272 KB Output is correct
78 Correct 188 ms 17276 KB Output is correct
79 Correct 212 ms 17504 KB Output is correct
80 Correct 191 ms 17460 KB Output is correct
81 Correct 186 ms 17280 KB Output is correct
82 Correct 197 ms 17272 KB Output is correct
83 Correct 191 ms 17456 KB Output is correct
84 Correct 199 ms 17444 KB Output is correct