답안 #1025528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025528 2024-07-17T06:17:04 Z 우민규(#10941) Cubeword (CEOI19_cubeword) C++17
100 / 100
288 ms 17236 KB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

const int SIGMA = 64;
const int MOD = 998244353;

int mul(int a, int b) { return (int64_t)a * (int64_t)b % MOD; }
int mul(int a, int b, int c) { return mul(mul(a, b), c); }
int mul(int a, int b, int c, int d) { return mul(mul(a, b), mul(c, d)); }
void add(int& a, int b) {
  a = ((int64_t)a + (int64_t)b) % MOD;
  //   if (a >= MOD) a -= MOD;
}
int id(char c) {
  if ('a' <= c && c <= 'z') return c - 'a';
  if ('A' <= c && c <= 'Z') return c - 'A' + 26;
  return c - '0' + 52;
  //   return 0;
}

int y[SIGMA][SIGMA][SIGMA];
int ways[8][SIGMA][SIGMA];

void solve() {
  int n;
  cin >> n;
  set<string> saw;
  for (int i = 0; i < n; ++i) {
    string cur;
    cin >> cur;

    string cur_rev = cur;
    reverse(cur_rev.begin(), cur_rev.end());

    saw.insert(cur);
    saw.insert(cur_rev);
  }

  for (auto& word : saw) {
    int cf = id(word.front()), cb = id(word.back());
    ways[word.size() - 3][cf][cb] += 1;
  }

  int tot_way = 0;
  for (auto& way : ways) {
    // do threes
    fill(&y[0][0][0], &y[0][0][0] + SIGMA * SIGMA * SIGMA, 0);
    // c1 <= c2 <= c3
    for (int c1 = 0; c1 < SIGMA; ++c1)
      for (int c2 = c1; c2 < SIGMA; ++c2)
        for (int c3 = c2; c3 < SIGMA; ++c3)
          for (int c4 = 0; c4 < SIGMA; ++c4)
            add(y[c1][c2][c3], mul(way[c1][c4], way[c2][c4], way[c3][c4]));

    // c1 <= c2 <= c3 <= c4
    int mul_factor_table[2][2][2] = {{{24, 12}, {12, 4}}, {{12, 6}, {4, 1}}};
    for (int c1 = 0; c1 < SIGMA; ++c1) {
      for (int c2 = c1; c2 < SIGMA; ++c2) {
        for (int c3 = c2; c3 < SIGMA; ++c3) {
          for (int c4 = c3; c4 < SIGMA; ++c4) {
            add(tot_way, mul(mul_factor_table[c1 == c2][c2 == c3][c3 == c4],
                             mul(y[c1][c2][c3], y[c1][c2][c4], y[c1][c3][c4],
                                 y[c2][c3][c4])));
          }
        }
      }
    }
  }
  cout << tot_way << "\n";
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int t = 1;

  while (t--) {
    solve();
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 242 ms 15748 KB Output is correct
2 Correct 245 ms 15956 KB Output is correct
3 Correct 257 ms 15860 KB Output is correct
4 Correct 240 ms 15952 KB Output is correct
5 Correct 247 ms 15956 KB Output is correct
6 Correct 249 ms 15972 KB Output is correct
7 Correct 250 ms 15956 KB Output is correct
8 Correct 266 ms 16212 KB Output is correct
9 Correct 243 ms 15760 KB Output is correct
10 Correct 250 ms 15980 KB Output is correct
11 Correct 263 ms 15872 KB Output is correct
12 Correct 246 ms 15932 KB Output is correct
13 Correct 253 ms 15956 KB Output is correct
14 Correct 243 ms 15952 KB Output is correct
15 Correct 240 ms 15976 KB Output is correct
16 Correct 250 ms 15764 KB Output is correct
17 Correct 250 ms 15772 KB Output is correct
18 Correct 240 ms 15828 KB Output is correct
19 Correct 241 ms 15960 KB Output is correct
20 Correct 243 ms 15960 KB Output is correct
21 Correct 253 ms 15952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 242 ms 15748 KB Output is correct
2 Correct 245 ms 15956 KB Output is correct
3 Correct 257 ms 15860 KB Output is correct
4 Correct 240 ms 15952 KB Output is correct
5 Correct 247 ms 15956 KB Output is correct
6 Correct 249 ms 15972 KB Output is correct
7 Correct 250 ms 15956 KB Output is correct
8 Correct 266 ms 16212 KB Output is correct
9 Correct 243 ms 15760 KB Output is correct
10 Correct 250 ms 15980 KB Output is correct
11 Correct 263 ms 15872 KB Output is correct
12 Correct 246 ms 15932 KB Output is correct
13 Correct 253 ms 15956 KB Output is correct
14 Correct 243 ms 15952 KB Output is correct
15 Correct 240 ms 15976 KB Output is correct
16 Correct 250 ms 15764 KB Output is correct
17 Correct 250 ms 15772 KB Output is correct
18 Correct 240 ms 15828 KB Output is correct
19 Correct 241 ms 15960 KB Output is correct
20 Correct 243 ms 15960 KB Output is correct
21 Correct 253 ms 15952 KB Output is correct
22 Correct 243 ms 16676 KB Output is correct
23 Correct 246 ms 16468 KB Output is correct
24 Correct 265 ms 16508 KB Output is correct
25 Correct 251 ms 16516 KB Output is correct
26 Correct 253 ms 16468 KB Output is correct
27 Correct 264 ms 16464 KB Output is correct
28 Correct 262 ms 16464 KB Output is correct
29 Correct 257 ms 16464 KB Output is correct
30 Correct 241 ms 16464 KB Output is correct
31 Correct 254 ms 16500 KB Output is correct
32 Correct 288 ms 16464 KB Output is correct
33 Correct 248 ms 16580 KB Output is correct
34 Correct 250 ms 16468 KB Output is correct
35 Correct 259 ms 16508 KB Output is correct
36 Correct 245 ms 16576 KB Output is correct
37 Correct 235 ms 16468 KB Output is correct
38 Correct 240 ms 16572 KB Output is correct
39 Correct 262 ms 16468 KB Output is correct
40 Correct 254 ms 16464 KB Output is correct
41 Correct 249 ms 16464 KB Output is correct
42 Correct 253 ms 16464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 242 ms 15748 KB Output is correct
2 Correct 245 ms 15956 KB Output is correct
3 Correct 257 ms 15860 KB Output is correct
4 Correct 240 ms 15952 KB Output is correct
5 Correct 247 ms 15956 KB Output is correct
6 Correct 249 ms 15972 KB Output is correct
7 Correct 250 ms 15956 KB Output is correct
8 Correct 266 ms 16212 KB Output is correct
9 Correct 243 ms 15760 KB Output is correct
10 Correct 250 ms 15980 KB Output is correct
11 Correct 263 ms 15872 KB Output is correct
12 Correct 246 ms 15932 KB Output is correct
13 Correct 253 ms 15956 KB Output is correct
14 Correct 243 ms 15952 KB Output is correct
15 Correct 240 ms 15976 KB Output is correct
16 Correct 250 ms 15764 KB Output is correct
17 Correct 250 ms 15772 KB Output is correct
18 Correct 240 ms 15828 KB Output is correct
19 Correct 241 ms 15960 KB Output is correct
20 Correct 243 ms 15960 KB Output is correct
21 Correct 253 ms 15952 KB Output is correct
22 Correct 243 ms 16676 KB Output is correct
23 Correct 246 ms 16468 KB Output is correct
24 Correct 265 ms 16508 KB Output is correct
25 Correct 251 ms 16516 KB Output is correct
26 Correct 253 ms 16468 KB Output is correct
27 Correct 264 ms 16464 KB Output is correct
28 Correct 262 ms 16464 KB Output is correct
29 Correct 257 ms 16464 KB Output is correct
30 Correct 241 ms 16464 KB Output is correct
31 Correct 254 ms 16500 KB Output is correct
32 Correct 288 ms 16464 KB Output is correct
33 Correct 248 ms 16580 KB Output is correct
34 Correct 250 ms 16468 KB Output is correct
35 Correct 259 ms 16508 KB Output is correct
36 Correct 245 ms 16576 KB Output is correct
37 Correct 235 ms 16468 KB Output is correct
38 Correct 240 ms 16572 KB Output is correct
39 Correct 262 ms 16468 KB Output is correct
40 Correct 254 ms 16464 KB Output is correct
41 Correct 249 ms 16464 KB Output is correct
42 Correct 253 ms 16464 KB Output is correct
43 Correct 256 ms 16708 KB Output is correct
44 Correct 260 ms 16928 KB Output is correct
45 Correct 257 ms 16720 KB Output is correct
46 Correct 239 ms 16728 KB Output is correct
47 Correct 251 ms 17192 KB Output is correct
48 Correct 243 ms 16768 KB Output is correct
49 Correct 244 ms 16720 KB Output is correct
50 Correct 230 ms 16724 KB Output is correct
51 Correct 245 ms 16724 KB Output is correct
52 Correct 274 ms 17012 KB Output is correct
53 Correct 248 ms 16768 KB Output is correct
54 Correct 264 ms 16776 KB Output is correct
55 Correct 263 ms 16980 KB Output is correct
56 Correct 249 ms 16724 KB Output is correct
57 Correct 251 ms 16836 KB Output is correct
58 Correct 248 ms 16908 KB Output is correct
59 Correct 256 ms 16724 KB Output is correct
60 Correct 233 ms 16900 KB Output is correct
61 Correct 242 ms 16684 KB Output is correct
62 Correct 236 ms 16908 KB Output is correct
63 Correct 254 ms 16980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 242 ms 15748 KB Output is correct
2 Correct 245 ms 15956 KB Output is correct
3 Correct 257 ms 15860 KB Output is correct
4 Correct 240 ms 15952 KB Output is correct
5 Correct 247 ms 15956 KB Output is correct
6 Correct 249 ms 15972 KB Output is correct
7 Correct 250 ms 15956 KB Output is correct
8 Correct 266 ms 16212 KB Output is correct
9 Correct 243 ms 15760 KB Output is correct
10 Correct 250 ms 15980 KB Output is correct
11 Correct 263 ms 15872 KB Output is correct
12 Correct 246 ms 15932 KB Output is correct
13 Correct 253 ms 15956 KB Output is correct
14 Correct 243 ms 15952 KB Output is correct
15 Correct 240 ms 15976 KB Output is correct
16 Correct 250 ms 15764 KB Output is correct
17 Correct 250 ms 15772 KB Output is correct
18 Correct 240 ms 15828 KB Output is correct
19 Correct 241 ms 15960 KB Output is correct
20 Correct 243 ms 15960 KB Output is correct
21 Correct 253 ms 15952 KB Output is correct
22 Correct 243 ms 16676 KB Output is correct
23 Correct 246 ms 16468 KB Output is correct
24 Correct 265 ms 16508 KB Output is correct
25 Correct 251 ms 16516 KB Output is correct
26 Correct 253 ms 16468 KB Output is correct
27 Correct 264 ms 16464 KB Output is correct
28 Correct 262 ms 16464 KB Output is correct
29 Correct 257 ms 16464 KB Output is correct
30 Correct 241 ms 16464 KB Output is correct
31 Correct 254 ms 16500 KB Output is correct
32 Correct 288 ms 16464 KB Output is correct
33 Correct 248 ms 16580 KB Output is correct
34 Correct 250 ms 16468 KB Output is correct
35 Correct 259 ms 16508 KB Output is correct
36 Correct 245 ms 16576 KB Output is correct
37 Correct 235 ms 16468 KB Output is correct
38 Correct 240 ms 16572 KB Output is correct
39 Correct 262 ms 16468 KB Output is correct
40 Correct 254 ms 16464 KB Output is correct
41 Correct 249 ms 16464 KB Output is correct
42 Correct 253 ms 16464 KB Output is correct
43 Correct 256 ms 16708 KB Output is correct
44 Correct 260 ms 16928 KB Output is correct
45 Correct 257 ms 16720 KB Output is correct
46 Correct 239 ms 16728 KB Output is correct
47 Correct 251 ms 17192 KB Output is correct
48 Correct 243 ms 16768 KB Output is correct
49 Correct 244 ms 16720 KB Output is correct
50 Correct 230 ms 16724 KB Output is correct
51 Correct 245 ms 16724 KB Output is correct
52 Correct 274 ms 17012 KB Output is correct
53 Correct 248 ms 16768 KB Output is correct
54 Correct 264 ms 16776 KB Output is correct
55 Correct 263 ms 16980 KB Output is correct
56 Correct 249 ms 16724 KB Output is correct
57 Correct 251 ms 16836 KB Output is correct
58 Correct 248 ms 16908 KB Output is correct
59 Correct 256 ms 16724 KB Output is correct
60 Correct 233 ms 16900 KB Output is correct
61 Correct 242 ms 16684 KB Output is correct
62 Correct 236 ms 16908 KB Output is correct
63 Correct 254 ms 16980 KB Output is correct
64 Correct 252 ms 16980 KB Output is correct
65 Correct 226 ms 16980 KB Output is correct
66 Correct 238 ms 17176 KB Output is correct
67 Correct 237 ms 17176 KB Output is correct
68 Correct 242 ms 17232 KB Output is correct
69 Correct 250 ms 16980 KB Output is correct
70 Correct 259 ms 16980 KB Output is correct
71 Correct 258 ms 16980 KB Output is correct
72 Correct 258 ms 16980 KB Output is correct
73 Correct 248 ms 17144 KB Output is correct
74 Correct 250 ms 16976 KB Output is correct
75 Correct 251 ms 16924 KB Output is correct
76 Correct 249 ms 17236 KB Output is correct
77 Correct 245 ms 16976 KB Output is correct
78 Correct 232 ms 16976 KB Output is correct
79 Correct 251 ms 16980 KB Output is correct
80 Correct 250 ms 16976 KB Output is correct
81 Correct 259 ms 16980 KB Output is correct
82 Correct 271 ms 16976 KB Output is correct
83 Correct 253 ms 16976 KB Output is correct
84 Correct 250 ms 17048 KB Output is correct