結果

問題 No.1011 Infinite Stairs
ユーザー kk
提出日時 2020-09-16 23:50:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,166 bytes
コンパイル時間 2,283 ms
コンパイル使用メモリ 201,188 KB
実行使用メモリ 8,248 KB
最終ジャッジ日時 2023-09-04 04:13:54
合計ジャッジ時間 9,036 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 32 ms
4,380 KB
testcase_03 TLE -
testcase_04 AC 329 ms
4,380 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

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];
      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;
      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