結果

問題 No.834 Random Walk Trip
ユーザー 0w10w1
提出日時 2019-08-02 01:28:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 2,228 ms
コンパイル使用メモリ 199,860 KB
実行使用メモリ 6,900 KB
最終ジャッジ日時 2023-09-18 18:08:09
合計ジャッジ時間 4,386 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 13 ms
4,384 KB
testcase_18 AC 34 ms
4,380 KB
testcase_19 AC 183 ms
6,852 KB
testcase_20 AC 33 ms
4,384 KB
testcase_21 AC 178 ms
6,644 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 144 ms
6,280 KB
testcase_24 AC 10 ms
4,376 KB
testcase_25 AC 182 ms
6,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MOD = 1e9 + 7;

int ipow(int v, int n, int m = MOD) {
  int r = 1;
  while (n) {
    if (n & 1) r = 1LL * r * v % m;
    v = 1LL * v * v % m;
    n >>= 1;
  }
  return r;
}

int inv(int v, int m = MOD) {
  return ipow(v, m - 2, m);
}

int main() {
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  vector<int> C_m(M + 1);
  C_m[0] = 1;
  for (int i = 0; i < M; ++i) {
    C_m[i + 1] = 1LL * C_m[i] * (M - i) % MOD * inv(i + 1) % MOD;
  } // m!/i!(m-i)! -> (m-i)/(i+1) * m!/i!(m-i)!

  int ans = 0;
  for (int i = 0; i < M + 1; ++i) {
    int x = i - (M - i);
    if (x < 0) {
      x = -x + 1;
    }
    if (x % (2 * N) < 2) {
      (ans += C_m[i]) %= MOD;
    }
  }

  cout << ans << endl;

  return 0;
}
0