結果

問題 No.1011 Infinite Stairs
ユーザー kk
提出日時 2020-09-16 23:53:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,665 ms / 2,000 ms
コード長 1,215 bytes
コンパイル時間 2,027 ms
コンパイル使用メモリ 201,728 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-24 11:20:59
合計ジャッジ時間 8,988 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 15 ms
4,376 KB
testcase_03 AC 1,056 ms
4,380 KB
testcase_04 AC 162 ms
4,380 KB
testcase_05 AC 1,665 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 9 ms
4,384 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 7 ms
4,380 KB
testcase_11 AC 194 ms
4,376 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 119 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 148 ms
4,376 KB
testcase_16 AC 716 ms
4,376 KB
testcase_17 AC 47 ms
4,376 KB
testcase_18 AC 417 ms
4,380 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 163 ms
4,376 KB
testcase_22 AC 324 ms
4,376 KB
testcase_23 AC 194 ms
4,376 KB
testcase_24 AC 206 ms
4,380 KB
testcase_25 AC 335 ms
4,380 KB
testcase_26 AC 69 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

const long long MOD = 1e9 + 7;

template <typename T>
class BIT {
  vector<T> bit;
public:
  BIT() {}
  // manage data in [1, n]
  BIT(int n) : bit(n + 1) {}
  
  void init() {
    fill(bit.begin(), bit.end(), 0);
  }
  
  // return sum in [1, i]
  T sum(int i){
    T s = 0;
    while(i > 0){
      s += bit[i];
      if (s >= MOD)
        s -= MOD;
      i -= i & -i;
    }
    return s;
  }
  
  // return sum in [l, r]
  T sum(int l, int r) {
    long long ret = sum(r) - sum(l-1);
    ret %= MOD;
    if (ret < 0)
      ret += MOD;
    return ret;
  }
  
  void add(int i, T x){
    while(i < (int)bit.size()){
      bit[i] += x;
      if (bit[i] >= MOD)
        bit[i] -= MOD;
      i += i & -i;
    }
  }
};

int n, d, k;

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

  cin >> n >> d >> k;
  BIT<long long> dp(k);

  --n;
  for (int i = 1; i <= d; i++)
    dp.add(i, 1);

  REP (i, n) {
    for (int j = k; j >= 1; j--) {
      long long cur = dp.sum(j, j);
      long long nxt = dp.sum(max(1, j-d), j-1);
      dp.add(j, nxt-cur);
    }
  }
  
  cout << dp.sum(k, k) << endl;
  
  
  return 0;
}
0