Submission #953582

# Submission time Handle Problem Language Result Execution time Memory
953582 2024-03-26T09:26:52 Z mircea_007 Cubeword (CEOI19_cubeword) C++17
84 / 100
185 ms 16512 KB
#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
1 Correct 142 ms 15304 KB Output is correct
2 Correct 159 ms 15280 KB Output is correct
3 Correct 148 ms 15192 KB Output is correct
4 Correct 143 ms 16228 KB Output is correct
5 Correct 162 ms 16424 KB Output is correct
6 Correct 128 ms 16068 KB Output is correct
7 Correct 137 ms 16064 KB Output is correct
8 Correct 153 ms 16128 KB Output is correct
9 Correct 144 ms 16072 KB Output is correct
10 Correct 157 ms 16068 KB Output is correct
11 Correct 139 ms 16036 KB Output is correct
12 Correct 151 ms 16328 KB Output is correct
13 Correct 135 ms 16068 KB Output is correct
14 Correct 136 ms 16068 KB Output is correct
15 Correct 134 ms 16132 KB Output is correct
16 Correct 148 ms 16068 KB Output is correct
17 Correct 138 ms 16064 KB Output is correct
18 Correct 134 ms 16220 KB Output is correct
19 Correct 147 ms 16068 KB Output is correct
20 Correct 154 ms 16064 KB Output is correct
21 Correct 141 ms 16204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 15304 KB Output is correct
2 Correct 159 ms 15280 KB Output is correct
3 Correct 148 ms 15192 KB Output is correct
4 Correct 143 ms 16228 KB Output is correct
5 Correct 162 ms 16424 KB Output is correct
6 Correct 128 ms 16068 KB Output is correct
7 Correct 137 ms 16064 KB Output is correct
8 Correct 153 ms 16128 KB Output is correct
9 Correct 144 ms 16072 KB Output is correct
10 Correct 157 ms 16068 KB Output is correct
11 Correct 139 ms 16036 KB Output is correct
12 Correct 151 ms 16328 KB Output is correct
13 Correct 135 ms 16068 KB Output is correct
14 Correct 136 ms 16068 KB Output is correct
15 Correct 134 ms 16132 KB Output is correct
16 Correct 148 ms 16068 KB Output is correct
17 Correct 138 ms 16064 KB Output is correct
18 Correct 134 ms 16220 KB Output is correct
19 Correct 147 ms 16068 KB Output is correct
20 Correct 154 ms 16064 KB Output is correct
21 Correct 141 ms 16204 KB Output is correct
22 Correct 130 ms 16068 KB Output is correct
23 Correct 131 ms 16192 KB Output is correct
24 Correct 185 ms 16512 KB Output is correct
25 Correct 134 ms 16232 KB Output is correct
26 Correct 139 ms 16128 KB Output is correct
27 Correct 136 ms 16064 KB Output is correct
28 Correct 135 ms 16068 KB Output is correct
29 Correct 133 ms 16112 KB Output is correct
30 Correct 149 ms 16252 KB Output is correct
31 Correct 136 ms 16068 KB Output is correct
32 Correct 151 ms 16072 KB Output is correct
33 Correct 131 ms 16236 KB Output is correct
34 Correct 142 ms 16072 KB Output is correct
35 Correct 144 ms 16232 KB Output is correct
36 Correct 139 ms 16068 KB Output is correct
37 Correct 147 ms 16064 KB Output is correct
38 Correct 144 ms 16072 KB Output is correct
39 Correct 131 ms 16080 KB Output is correct
40 Correct 131 ms 16228 KB Output is correct
41 Correct 133 ms 16092 KB Output is correct
42 Correct 136 ms 16244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 15304 KB Output is correct
2 Correct 159 ms 15280 KB Output is correct
3 Correct 148 ms 15192 KB Output is correct
4 Correct 143 ms 16228 KB Output is correct
5 Correct 162 ms 16424 KB Output is correct
6 Correct 128 ms 16068 KB Output is correct
7 Correct 137 ms 16064 KB Output is correct
8 Correct 153 ms 16128 KB Output is correct
9 Correct 144 ms 16072 KB Output is correct
10 Correct 157 ms 16068 KB Output is correct
11 Correct 139 ms 16036 KB Output is correct
12 Correct 151 ms 16328 KB Output is correct
13 Correct 135 ms 16068 KB Output is correct
14 Correct 136 ms 16068 KB Output is correct
15 Correct 134 ms 16132 KB Output is correct
16 Correct 148 ms 16068 KB Output is correct
17 Correct 138 ms 16064 KB Output is correct
18 Correct 134 ms 16220 KB Output is correct
19 Correct 147 ms 16068 KB Output is correct
20 Correct 154 ms 16064 KB Output is correct
21 Correct 141 ms 16204 KB Output is correct
22 Correct 130 ms 16068 KB Output is correct
23 Correct 131 ms 16192 KB Output is correct
24 Correct 185 ms 16512 KB Output is correct
25 Correct 134 ms 16232 KB Output is correct
26 Correct 139 ms 16128 KB Output is correct
27 Correct 136 ms 16064 KB Output is correct
28 Correct 135 ms 16068 KB Output is correct
29 Correct 133 ms 16112 KB Output is correct
30 Correct 149 ms 16252 KB Output is correct
31 Correct 136 ms 16068 KB Output is correct
32 Correct 151 ms 16072 KB Output is correct
33 Correct 131 ms 16236 KB Output is correct
34 Correct 142 ms 16072 KB Output is correct
35 Correct 144 ms 16232 KB Output is correct
36 Correct 139 ms 16068 KB Output is correct
37 Correct 147 ms 16064 KB Output is correct
38 Correct 144 ms 16072 KB Output is correct
39 Correct 131 ms 16080 KB Output is correct
40 Correct 131 ms 16228 KB Output is correct
41 Correct 133 ms 16092 KB Output is correct
42 Correct 136 ms 16244 KB Output is correct
43 Correct 131 ms 16252 KB Output is correct
44 Correct 135 ms 16296 KB Output is correct
45 Correct 134 ms 16236 KB Output is correct
46 Correct 173 ms 16248 KB Output is correct
47 Correct 133 ms 16252 KB Output is correct
48 Correct 131 ms 16256 KB Output is correct
49 Correct 147 ms 16252 KB Output is correct
50 Correct 131 ms 16384 KB Output is correct
51 Correct 131 ms 16372 KB Output is correct
52 Correct 168 ms 16368 KB Output is correct
53 Correct 142 ms 16380 KB Output is correct
54 Correct 142 ms 16252 KB Output is correct
55 Correct 158 ms 16508 KB Output is correct
56 Correct 131 ms 16376 KB Output is correct
57 Correct 155 ms 16312 KB Output is correct
58 Correct 168 ms 16172 KB Output is correct
59 Correct 133 ms 16296 KB Output is correct
60 Correct 146 ms 16504 KB Output is correct
61 Correct 130 ms 16248 KB Output is correct
62 Correct 130 ms 16236 KB Output is correct
63 Correct 131 ms 16280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 15304 KB Output is correct
2 Correct 159 ms 15280 KB Output is correct
3 Correct 148 ms 15192 KB Output is correct
4 Correct 143 ms 16228 KB Output is correct
5 Correct 162 ms 16424 KB Output is correct
6 Correct 128 ms 16068 KB Output is correct
7 Correct 137 ms 16064 KB Output is correct
8 Correct 153 ms 16128 KB Output is correct
9 Correct 144 ms 16072 KB Output is correct
10 Correct 157 ms 16068 KB Output is correct
11 Correct 139 ms 16036 KB Output is correct
12 Correct 151 ms 16328 KB Output is correct
13 Correct 135 ms 16068 KB Output is correct
14 Correct 136 ms 16068 KB Output is correct
15 Correct 134 ms 16132 KB Output is correct
16 Correct 148 ms 16068 KB Output is correct
17 Correct 138 ms 16064 KB Output is correct
18 Correct 134 ms 16220 KB Output is correct
19 Correct 147 ms 16068 KB Output is correct
20 Correct 154 ms 16064 KB Output is correct
21 Correct 141 ms 16204 KB Output is correct
22 Correct 130 ms 16068 KB Output is correct
23 Correct 131 ms 16192 KB Output is correct
24 Correct 185 ms 16512 KB Output is correct
25 Correct 134 ms 16232 KB Output is correct
26 Correct 139 ms 16128 KB Output is correct
27 Correct 136 ms 16064 KB Output is correct
28 Correct 135 ms 16068 KB Output is correct
29 Correct 133 ms 16112 KB Output is correct
30 Correct 149 ms 16252 KB Output is correct
31 Correct 136 ms 16068 KB Output is correct
32 Correct 151 ms 16072 KB Output is correct
33 Correct 131 ms 16236 KB Output is correct
34 Correct 142 ms 16072 KB Output is correct
35 Correct 144 ms 16232 KB Output is correct
36 Correct 139 ms 16068 KB Output is correct
37 Correct 147 ms 16064 KB Output is correct
38 Correct 144 ms 16072 KB Output is correct
39 Correct 131 ms 16080 KB Output is correct
40 Correct 131 ms 16228 KB Output is correct
41 Correct 133 ms 16092 KB Output is correct
42 Correct 136 ms 16244 KB Output is correct
43 Correct 131 ms 16252 KB Output is correct
44 Correct 135 ms 16296 KB Output is correct
45 Correct 134 ms 16236 KB Output is correct
46 Correct 173 ms 16248 KB Output is correct
47 Correct 133 ms 16252 KB Output is correct
48 Correct 131 ms 16256 KB Output is correct
49 Correct 147 ms 16252 KB Output is correct
50 Correct 131 ms 16384 KB Output is correct
51 Correct 131 ms 16372 KB Output is correct
52 Correct 168 ms 16368 KB Output is correct
53 Correct 142 ms 16380 KB Output is correct
54 Correct 142 ms 16252 KB Output is correct
55 Correct 158 ms 16508 KB Output is correct
56 Correct 131 ms 16376 KB Output is correct
57 Correct 155 ms 16312 KB Output is correct
58 Correct 168 ms 16172 KB Output is correct
59 Correct 133 ms 16296 KB Output is correct
60 Correct 146 ms 16504 KB Output is correct
61 Correct 130 ms 16248 KB Output is correct
62 Correct 130 ms 16236 KB Output is correct
63 Correct 131 ms 16280 KB Output is correct
64 Incorrect 136 ms 16508 KB Output isn't correct
65 Halted 0 ms 0 KB -