結果

問題 No.1011 Infinite Stairs
ユーザー StrorkisStrorkis
提出日時 2020-03-20 22:00:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 856 bytes
コンパイル時間 497 ms
コンパイル使用メモリ 65,068 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-24 10:57:52
合計ジャッジ時間 2,088 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 98 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 148 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 14 ms
4,380 KB
testcase_16 AC 46 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 36 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 12 ms
4,376 KB
testcase_22 AC 13 ms
4,376 KB
testcase_23 AC 18 ms
4,376 KB
testcase_24 AC 22 ms
4,376 KB
testcase_25 AC 28 ms
4,376 KB
testcase_26 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
using ll = long long;
const int MOD = 1000000007;

ll pow(ll a, ll n) {
  ll res = 1;
  for (; n; n >>= 1) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}

ll fact(int n) {
  ll res = 1;
  for (int i = 2; i <= n; i++)
    res = res * i % MOD;
  return res;
}

ll comb(ll n, ll r) {
  ll tmp = 1;
  for (int i = n; i > n - r; i--) tmp = tmp * i % MOD;
  ll inv_fact_r = pow(fact(r), MOD-2);
  return tmp * inv_fact_r % MOD;
}

ll hcomb(ll n, ll r) {
    return comb(n+r-1, r);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, d, K; cin >> N >> d >> K;
    ll ans = 0;
    for (int i = 0; i <= (K-N)/d; i++) {
        ans += pow(-1, i) * comb(N, i) * hcomb(N, K-N-d*i);
        ans %= MOD;
        while (ans < 0) ans += MOD;
    }
    cout << ans << "\n";
}
0