結果

問題 No.660 家を通り過ぎないランダムウォーク問題
ユーザー 0w10w1
提出日時 2018-04-06 23:03:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 1,950 ms
コンパイル使用メモリ 198,572 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2023-09-08 18:05:22
合計ジャッジ時間 4,406 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
7,460 KB
testcase_01 AC 10 ms
7,468 KB
testcase_02 AC 9 ms
7,424 KB
testcase_03 AC 9 ms
7,400 KB
testcase_04 AC 10 ms
7,464 KB
testcase_05 AC 9 ms
7,716 KB
testcase_06 AC 9 ms
7,408 KB
testcase_07 AC 10 ms
7,588 KB
testcase_08 AC 9 ms
7,656 KB
testcase_09 AC 9 ms
7,608 KB
testcase_10 AC 9 ms
7,424 KB
testcase_11 AC 9 ms
7,592 KB
testcase_12 AC 10 ms
7,412 KB
testcase_13 AC 9 ms
7,480 KB
testcase_14 AC 9 ms
7,496 KB
testcase_15 AC 9 ms
7,404 KB
testcase_16 AC 9 ms
7,468 KB
testcase_17 AC 9 ms
7,652 KB
testcase_18 AC 10 ms
7,400 KB
testcase_19 AC 9 ms
7,424 KB
testcase_20 AC 9 ms
7,540 KB
testcase_21 AC 10 ms
7,556 KB
testcase_22 AC 10 ms
7,404 KB
testcase_23 AC 10 ms
7,536 KB
testcase_24 AC 10 ms
7,396 KB
testcase_25 AC 9 ms
7,412 KB
testcase_26 AC 9 ms
7,488 KB
testcase_27 AC 9 ms
7,408 KB
testcase_28 AC 9 ms
7,468 KB
testcase_29 AC 9 ms
7,608 KB
testcase_30 AC 9 ms
7,672 KB
testcase_31 AC 10 ms
7,468 KB
testcase_32 AC 9 ms
7,488 KB
testcase_33 AC 9 ms
7,612 KB
testcase_34 AC 9 ms
7,468 KB
testcase_35 AC 10 ms
7,412 KB
testcase_36 AC 10 ms
7,524 KB
testcase_37 AC 10 ms
7,492 KB
testcase_38 AC 10 ms
7,576 KB
testcase_39 AC 10 ms
7,524 KB
testcase_40 AC 10 ms
7,400 KB
testcase_41 AC 10 ms
7,476 KB
testcase_42 AC 10 ms
7,616 KB
testcase_43 AC 10 ms
7,396 KB
testcase_44 AC 10 ms
7,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int M = int(1e9) + 7;

int f[1 << 19], vf[1 << 19];

int int_pow(int v, int p) {
  int r = 1;
  for (int i = p; i; i >>= 1) {
    if (i & 1) r = 1LL * r * v % M;
    v = 1LL * v * v % M;
  }
  return r;
}

int cmb(int n, int m) {
  return 1LL * f[n] * vf[m] % M * vf[n - m] % M;
}

signed main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = f[0] = 1; i < 1 << 19; ++i) {
    f[i] = 1LL * f[i - 1] * i % M;
  }
  vf[(1 << 19) - 1] = int_pow(f[(1 << 19) - 1], M - 2);
  for (int i = (1 << 19) - 2; ~i; --i) {
    vf[i] = 1LL * vf[i + 1] * (i + 1) % M;
  }
  int ans = 1;
  for (int i = N + 2; i <= 2 * N; i += 2) {
    int r = i - N >> 1;
    (ans += (cmb(i - 1, r) - cmb(i - 1, r - 1)) % M) %= M;
  }
  if (ans < 0) ans += M;
  cout << ans << endl;
  return 0;
}
0