답안 #845168

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
845168 2023-09-06T12:24:37 Z vjudge1 Trener (COCI20_trener) C++17
110 / 110
62 ms 5720 KB
// author: erray
#include <bits/stdc++.h>

#ifdef DEBUG
  #include "debug.h"
#else
  #define debug(...) void(37)
#endif

using namespace std;

constexpr int md = int(1e9) + 7;
int add(int x, int y) {
  if ((x += y) >= md) {
    x -= md;
  }
  return x;
}
int mul(int x, int y) {
  return 1LL * x * y % md;
}
constexpr int base = 31;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  array<int, 26> hv{};
  iota(hv.begin(), hv.end(), 0);
  random_shuffle(hv.begin(), hv.end());
  int N, K;
  cin >> N >> K;
  vector<vector<string>> S(N, vector<string>(K));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < K; ++j) {
      cin >> S[i][j];
    }
  }
  map<int, int> ans;
  for (int i = 0; i < N; ++i) {
    map<int, int> next_ans;
    for (int j = 0; j < K; ++j) {
      int h = 0, L = -1;
      for (int k = 0; k <= i; ++k) {
        h = mul(h, base);
        h = add(h, hv[S[i][j][k] - 'a']);  
        if (k == i - 1) {
          L = h;
        }
      }
      int R = 0;
      for (int k = 1; k <= i; ++k) {
        R = mul(R, base);
        R = add(R, hv[S[i][j][k] - 'a']);
      }
      int res = (i == 0);
      res = add(res, ans[L]);
      if (R != L) {
        res = add(res, ans[R]);
      }
      next_ans[h] = add(next_ans[h], res);
    } 
    swap(ans, next_ans);
  } 
  int p = 0;
  for (auto[foo, x] : ans) {
    p = add(p, x);
  }
  cout << p << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 600 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 4 ms 600 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 60 ms 5720 KB Output is correct
13 Correct 57 ms 5720 KB Output is correct
14 Correct 56 ms 5720 KB Output is correct
15 Correct 62 ms 5720 KB Output is correct
16 Correct 29 ms 5508 KB Output is correct
17 Correct 51 ms 5464 KB Output is correct
18 Correct 51 ms 5464 KB Output is correct
19 Correct 52 ms 5676 KB Output is correct
20 Correct 52 ms 5464 KB Output is correct
21 Correct 50 ms 5464 KB Output is correct
22 Correct 29 ms 5464 KB Output is correct