Submission #788621

# Submission time Handle Problem Language Result Execution time Memory
788621 2023-07-20T12:19:07 Z WLZ Cubeword (CEOI19_cubeword) C++17
100 / 100
348 ms 8252 KB
#include <bits/stdc++.h>
using namespace std;

const long long MOD = 998244353ll;
const int MX = 62;
const vector<long long> fact = {1, 1, 2, 6, 24};

int to_int(char c) {
  if (c <= '9') {
    return c - '0';
  }
  if (c <= 'Z') {
    return c - 'A' + 10;
  }
  return c - 'a' + 36;
}

void add(long long& a, long long b) {
  a += b;
  if (a >= MOD) {
    a -= MOD;
  }
}

long long mul(long long a, long long b) {
  return (a * b) % MOD;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector< vector<string> > in(11);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    in[(int) s.length()].push_back(s);
  }
  long long ans = 0;
  for (int len = 3; len <= 10; len++) {
    if (in[len].empty()) {
      continue;
    }
    vector< vector<long long> > v(MX, vector<long long>(MX));
    vector<int> ch;
    set<string> st;
    for (auto& s : in[len]) {
      string t = s;
      reverse(t.begin(), t.end());
      if (st.count(t)) {
        continue;
      }
      int a = to_int(s[0]);
      ch.push_back(a);
      int b = to_int(s.back());
      ch.push_back(b);
      if (a == b) {
        if (s == t) {
          add(v[a][a], 1);
        } else {
          add(v[a][a], 2);
        }
      } else {
        add(v[a][b], 1);
        add(v[b][a], 1);
      }
      st.insert(s);
    }
    sort(ch.begin(), ch.end());
    ch.erase(unique(ch.begin(), ch.end()), ch.end());
    int m = (int) ch.size();
    vector< vector< vector<long long> > > d(MX, vector< vector<long long> >(MX, vector<long long>(MX, 0)));
    for (int i1 = 0; i1 < m; i1++) {
      int a = ch[i1];
      for (int i2 = i1; i2 < m; i2++) {
        int b = ch[i2];
        for (int i3 = i2; i3 < m; i3++) {
          int c = ch[i3];
          for (int j = 0; j < m; j++) {
            int k = ch[j];
            add(d[a][b][c], mul(v[a][k], mul(v[b][k], v[c][k])));
          }
          d[a][c][b] = d[b][a][c] = d[b][c][a] = d[c][a][b] = d[c][b][a] = d[a][b][c];
        }
      }
    }
    for (int i1 = 0; i1 < m; i1++) {
      int a = ch[i1];
      for (int i2 = i1; i2 < m; i2++) {
        int b = ch[i2];
        for (int i3 = i2; i3 < m; i3++) {
          int c = ch[i3];
          for (int i4 = i3; i4 < m; i4++) {
            int k = ch[i4];
            vector<int> tmp(4);
            tmp[0] = a; tmp[1] = b; tmp[2] = c; tmp[3] = k;
            sort(tmp.begin(), tmp.end());
            long long div = 24ll;
            int cur = 1;
            for (int i = 1; i < 4; i++) {
              if (tmp[i] == tmp[i - 1]) {
                cur++;
              } else {
                div /= fact[cur];
                cur = 1;
              }
            }
            div /= fact[cur];
            add(ans, mul(div, mul(d[a][b][c], mul(d[a][b][k], mul(d[a][c][k], d[b][c][k])))));
          }
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 52 ms 8064 KB Output is correct
2 Correct 56 ms 8088 KB Output is correct
3 Correct 50 ms 8036 KB Output is correct
4 Correct 50 ms 8116 KB Output is correct
5 Correct 50 ms 8072 KB Output is correct
6 Correct 50 ms 8092 KB Output is correct
7 Correct 50 ms 8100 KB Output is correct
8 Correct 51 ms 8084 KB Output is correct
9 Correct 50 ms 8076 KB Output is correct
10 Correct 64 ms 8080 KB Output is correct
11 Correct 51 ms 8156 KB Output is correct
12 Correct 55 ms 8252 KB Output is correct
13 Correct 51 ms 8188 KB Output is correct
14 Correct 51 ms 8224 KB Output is correct
15 Correct 56 ms 8116 KB Output is correct
16 Correct 50 ms 8036 KB Output is correct
17 Correct 50 ms 8120 KB Output is correct
18 Correct 51 ms 8032 KB Output is correct
19 Correct 50 ms 8112 KB Output is correct
20 Correct 54 ms 8092 KB Output is correct
21 Correct 52 ms 8064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 8064 KB Output is correct
2 Correct 56 ms 8088 KB Output is correct
3 Correct 50 ms 8036 KB Output is correct
4 Correct 50 ms 8116 KB Output is correct
5 Correct 50 ms 8072 KB Output is correct
6 Correct 50 ms 8092 KB Output is correct
7 Correct 50 ms 8100 KB Output is correct
8 Correct 51 ms 8084 KB Output is correct
9 Correct 50 ms 8076 KB Output is correct
10 Correct 64 ms 8080 KB Output is correct
11 Correct 51 ms 8156 KB Output is correct
12 Correct 55 ms 8252 KB Output is correct
13 Correct 51 ms 8188 KB Output is correct
14 Correct 51 ms 8224 KB Output is correct
15 Correct 56 ms 8116 KB Output is correct
16 Correct 50 ms 8036 KB Output is correct
17 Correct 50 ms 8120 KB Output is correct
18 Correct 51 ms 8032 KB Output is correct
19 Correct 50 ms 8112 KB Output is correct
20 Correct 54 ms 8092 KB Output is correct
21 Correct 52 ms 8064 KB Output is correct
22 Correct 52 ms 7568 KB Output is correct
23 Correct 52 ms 7520 KB Output is correct
24 Correct 53 ms 7520 KB Output is correct
25 Correct 52 ms 7544 KB Output is correct
26 Correct 53 ms 7528 KB Output is correct
27 Correct 56 ms 7548 KB Output is correct
28 Correct 52 ms 7536 KB Output is correct
29 Correct 51 ms 7560 KB Output is correct
30 Correct 51 ms 7532 KB Output is correct
31 Correct 51 ms 7560 KB Output is correct
32 Correct 52 ms 7504 KB Output is correct
33 Correct 52 ms 7520 KB Output is correct
34 Correct 53 ms 7544 KB Output is correct
35 Correct 79 ms 7548 KB Output is correct
36 Correct 64 ms 7516 KB Output is correct
37 Correct 51 ms 7556 KB Output is correct
38 Correct 65 ms 7556 KB Output is correct
39 Correct 66 ms 7540 KB Output is correct
40 Correct 52 ms 7540 KB Output is correct
41 Correct 51 ms 7492 KB Output is correct
42 Correct 56 ms 7632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 8064 KB Output is correct
2 Correct 56 ms 8088 KB Output is correct
3 Correct 50 ms 8036 KB Output is correct
4 Correct 50 ms 8116 KB Output is correct
5 Correct 50 ms 8072 KB Output is correct
6 Correct 50 ms 8092 KB Output is correct
7 Correct 50 ms 8100 KB Output is correct
8 Correct 51 ms 8084 KB Output is correct
9 Correct 50 ms 8076 KB Output is correct
10 Correct 64 ms 8080 KB Output is correct
11 Correct 51 ms 8156 KB Output is correct
12 Correct 55 ms 8252 KB Output is correct
13 Correct 51 ms 8188 KB Output is correct
14 Correct 51 ms 8224 KB Output is correct
15 Correct 56 ms 8116 KB Output is correct
16 Correct 50 ms 8036 KB Output is correct
17 Correct 50 ms 8120 KB Output is correct
18 Correct 51 ms 8032 KB Output is correct
19 Correct 50 ms 8112 KB Output is correct
20 Correct 54 ms 8092 KB Output is correct
21 Correct 52 ms 8064 KB Output is correct
22 Correct 52 ms 7568 KB Output is correct
23 Correct 52 ms 7520 KB Output is correct
24 Correct 53 ms 7520 KB Output is correct
25 Correct 52 ms 7544 KB Output is correct
26 Correct 53 ms 7528 KB Output is correct
27 Correct 56 ms 7548 KB Output is correct
28 Correct 52 ms 7536 KB Output is correct
29 Correct 51 ms 7560 KB Output is correct
30 Correct 51 ms 7532 KB Output is correct
31 Correct 51 ms 7560 KB Output is correct
32 Correct 52 ms 7504 KB Output is correct
33 Correct 52 ms 7520 KB Output is correct
34 Correct 53 ms 7544 KB Output is correct
35 Correct 79 ms 7548 KB Output is correct
36 Correct 64 ms 7516 KB Output is correct
37 Correct 51 ms 7556 KB Output is correct
38 Correct 65 ms 7556 KB Output is correct
39 Correct 66 ms 7540 KB Output is correct
40 Correct 52 ms 7540 KB Output is correct
41 Correct 51 ms 7492 KB Output is correct
42 Correct 56 ms 7632 KB Output is correct
43 Correct 70 ms 7512 KB Output is correct
44 Correct 69 ms 7604 KB Output is correct
45 Correct 67 ms 7408 KB Output is correct
46 Correct 71 ms 7520 KB Output is correct
47 Correct 73 ms 7424 KB Output is correct
48 Correct 73 ms 7404 KB Output is correct
49 Correct 88 ms 7400 KB Output is correct
50 Correct 71 ms 7444 KB Output is correct
51 Correct 72 ms 7416 KB Output is correct
52 Correct 80 ms 7516 KB Output is correct
53 Correct 69 ms 7552 KB Output is correct
54 Correct 72 ms 7616 KB Output is correct
55 Correct 69 ms 7396 KB Output is correct
56 Correct 99 ms 7600 KB Output is correct
57 Correct 73 ms 7424 KB Output is correct
58 Correct 69 ms 7412 KB Output is correct
59 Correct 68 ms 7400 KB Output is correct
60 Correct 73 ms 7424 KB Output is correct
61 Correct 70 ms 7384 KB Output is correct
62 Correct 86 ms 7412 KB Output is correct
63 Correct 83 ms 7428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 8064 KB Output is correct
2 Correct 56 ms 8088 KB Output is correct
3 Correct 50 ms 8036 KB Output is correct
4 Correct 50 ms 8116 KB Output is correct
5 Correct 50 ms 8072 KB Output is correct
6 Correct 50 ms 8092 KB Output is correct
7 Correct 50 ms 8100 KB Output is correct
8 Correct 51 ms 8084 KB Output is correct
9 Correct 50 ms 8076 KB Output is correct
10 Correct 64 ms 8080 KB Output is correct
11 Correct 51 ms 8156 KB Output is correct
12 Correct 55 ms 8252 KB Output is correct
13 Correct 51 ms 8188 KB Output is correct
14 Correct 51 ms 8224 KB Output is correct
15 Correct 56 ms 8116 KB Output is correct
16 Correct 50 ms 8036 KB Output is correct
17 Correct 50 ms 8120 KB Output is correct
18 Correct 51 ms 8032 KB Output is correct
19 Correct 50 ms 8112 KB Output is correct
20 Correct 54 ms 8092 KB Output is correct
21 Correct 52 ms 8064 KB Output is correct
22 Correct 52 ms 7568 KB Output is correct
23 Correct 52 ms 7520 KB Output is correct
24 Correct 53 ms 7520 KB Output is correct
25 Correct 52 ms 7544 KB Output is correct
26 Correct 53 ms 7528 KB Output is correct
27 Correct 56 ms 7548 KB Output is correct
28 Correct 52 ms 7536 KB Output is correct
29 Correct 51 ms 7560 KB Output is correct
30 Correct 51 ms 7532 KB Output is correct
31 Correct 51 ms 7560 KB Output is correct
32 Correct 52 ms 7504 KB Output is correct
33 Correct 52 ms 7520 KB Output is correct
34 Correct 53 ms 7544 KB Output is correct
35 Correct 79 ms 7548 KB Output is correct
36 Correct 64 ms 7516 KB Output is correct
37 Correct 51 ms 7556 KB Output is correct
38 Correct 65 ms 7556 KB Output is correct
39 Correct 66 ms 7540 KB Output is correct
40 Correct 52 ms 7540 KB Output is correct
41 Correct 51 ms 7492 KB Output is correct
42 Correct 56 ms 7632 KB Output is correct
43 Correct 70 ms 7512 KB Output is correct
44 Correct 69 ms 7604 KB Output is correct
45 Correct 67 ms 7408 KB Output is correct
46 Correct 71 ms 7520 KB Output is correct
47 Correct 73 ms 7424 KB Output is correct
48 Correct 73 ms 7404 KB Output is correct
49 Correct 88 ms 7400 KB Output is correct
50 Correct 71 ms 7444 KB Output is correct
51 Correct 72 ms 7416 KB Output is correct
52 Correct 80 ms 7516 KB Output is correct
53 Correct 69 ms 7552 KB Output is correct
54 Correct 72 ms 7616 KB Output is correct
55 Correct 69 ms 7396 KB Output is correct
56 Correct 99 ms 7600 KB Output is correct
57 Correct 73 ms 7424 KB Output is correct
58 Correct 69 ms 7412 KB Output is correct
59 Correct 68 ms 7400 KB Output is correct
60 Correct 73 ms 7424 KB Output is correct
61 Correct 70 ms 7384 KB Output is correct
62 Correct 86 ms 7412 KB Output is correct
63 Correct 83 ms 7428 KB Output is correct
64 Correct 293 ms 7400 KB Output is correct
65 Correct 291 ms 7428 KB Output is correct
66 Correct 348 ms 7392 KB Output is correct
67 Correct 304 ms 7520 KB Output is correct
68 Correct 294 ms 7516 KB Output is correct
69 Correct 303 ms 7364 KB Output is correct
70 Correct 287 ms 7400 KB Output is correct
71 Correct 302 ms 7564 KB Output is correct
72 Correct 301 ms 7364 KB Output is correct
73 Correct 307 ms 7376 KB Output is correct
74 Correct 333 ms 7384 KB Output is correct
75 Correct 319 ms 7400 KB Output is correct
76 Correct 304 ms 7404 KB Output is correct
77 Correct 306 ms 7392 KB Output is correct
78 Correct 292 ms 7372 KB Output is correct
79 Correct 295 ms 7400 KB Output is correct
80 Correct 300 ms 7348 KB Output is correct
81 Correct 294 ms 7588 KB Output is correct
82 Correct 309 ms 7384 KB Output is correct
83 Correct 288 ms 7396 KB Output is correct
84 Correct 301 ms 7368 KB Output is correct