| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 212165 | zimpha | 유적 3 (JOI20_ruins3) | C++17 | 309 ms | 6648 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <vector>
#include <algorithm>
using int64 = long long;
const int N = 2e3 + 10;
const int mod = 1e9 + 7, i2 = 500000004;
int binom[N][N], ways[N][N];
void add(int &x, int y) {
  if ((x += y) >= mod) x -= mod;
}
int main() {
  int n;
  scanf("%d", &n);
  std::vector<bool> mark(n * 2);
  for (int i = 0, x; i < n; ++i) {
    scanf("%d", &x);
    mark[x - 1] = true;
  }
  for (int i = 0; i <= n; ++i) {
    binom[i][0] = binom[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      binom[i][j] = (binom[i - 1][j] + binom[i - 1][j - 1]) % mod;
    }
  }
  ways[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j) {
      ways[i][j] = (int64)ways[i - 1][j] % mod;
      if (j >= 1) add(ways[i][j], (int64)ways[i - 1][j - 1] * j * 2 % mod);
      if (j >= 2) add(ways[i][j], (int64)ways[i - 1][j - 2] * j * (j - 1) % mod);
    }
  }
  std::vector<int> f(n + 1), g(n + 1);
  f[0] = 1;
  int c0 = 0, c1 = 0;
  for (int i = n * 2 - 1; i >= 0; --i) {
    std::fill(g.begin(), g.end(), 0);
    if (mark[i]) {
      for (int j = c0; j <= c1; ++j) if (f[j]) {
        add(g[j], f[j]);
        for (int k = j + 1; k <= c1 + 1; ++k) {
          add(g[k], (int64)f[j] * binom[c1 - j][k - j - 1] % mod * ways[k - j - 1][k - j - 1] % mod * (k - j + 1) % mod % mod);
        }
      }
      ++c1;
    } else {
      for (int j = c0; j <= c1; ++j) if (f[j]) {
        add(g[j], (int64)f[j] * (j - c0) % mod);
      }
      ++c0;
    }
    f.swap(g);
  }
  int ret = f.back();
  for (int i = 0; i < n; ++i) ret = (int64)ret * i2 % mod;
  printf("%d\n", ret);
  return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
