結果

問題 No.1011 Infinite Stairs
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2020-08-25 18:56:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 352 ms / 2,000 ms
コード長 2,938 bytes
コンパイル時間 931 ms
コンパイル使用メモリ 80,880 KB
実行使用メモリ 215,496 KB
最終ジャッジ日時 2023-09-24 11:20:38
合計ジャッジ時間 3,406 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 6 ms
6,004 KB
testcase_03 AC 229 ms
143,236 KB
testcase_04 AC 45 ms
26,528 KB
testcase_05 AC 352 ms
215,496 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 5 ms
4,852 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 54 ms
31,528 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 33 ms
20,524 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 41 ms
25,676 KB
testcase_16 AC 171 ms
100,920 KB
testcase_17 AC 17 ms
11,280 KB
testcase_18 AC 96 ms
59,568 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 41 ms
26,040 KB
testcase_22 AC 84 ms
49,192 KB
testcase_23 AC 49 ms
30,452 KB
testcase_24 AC 52 ms
33,464 KB
testcase_25 AC 85 ms
52,388 KB
testcase_26 AC 19 ms
13,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<vector>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
#define rep(i, n) for (i32 i = 0; i < (i32)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
constexpr i64 MAX = 10000000;
constexpr i64 MOD = 1000000007;
i64 fac[MAX], finv[MAX], inv[MAX];
template <i64 modulus>
class modcal
{

public:
  i64 a;

  constexpr modcal(const i64 x = 0) noexcept : a(x % modulus) {}
  constexpr i64 &value() noexcept { return a; }
  constexpr const i64 &value() const noexcept { return a; }
  constexpr modcal operator+(const modcal rhs) const noexcept
  {
    return modcal(*this) += rhs;
  }
  constexpr modcal operator-(const modcal rhs) const noexcept
  {
    return modcal(*this) -= rhs;
  }
  constexpr modcal operator*(const modcal rhs) const noexcept
  {
    return modcal(*this) *= rhs;
  }
  constexpr modcal operator/(const modcal rhs) noexcept
  {
    return modcal(*this) /= rhs;
  }
  constexpr modcal &operator+=(const modcal rhs) noexcept
  {
    a += rhs.a;
    if (a >= modulus)
    {
      a -= modulus;
    }
    return *this;
  }
  constexpr modcal &operator-=(const modcal rhs) noexcept
  {
    if (a < rhs.a)
    {
      a += modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modcal &operator*=(const modcal rhs) noexcept
  {
    a = a * rhs.a % modulus;
    return *this;
  }
  constexpr modcal &operator/=(modcal rhs) noexcept
  {
    i64 exp = modulus - 2;
    while (exp)
    {
      if (exp % 2)
      {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }

  void COMninit()
  {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
      fac[i] = fac[i - 1] * i % modulus;
      inv[i] = MOD - inv[modulus % i] * (modulus / i) % modulus;
      finv[i] = finv[i - 1] * inv[i] % modulus;
    }
  }
  i64 COMn(i64 n, i64 k)
  {
    if (n < k)
      return 0;
    if (n < 0 || k < 0)
      return 0;
    return fac[n] * (finv[k] * finv[n - k] % modulus) % modulus;
  }
  constexpr modcal<1000000007> modpow(const modcal<1000000007> &a, i64 n)
  {
    if (n == 0)
      return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1)
      t = t * a;
    return t;
  }
};
using modc = modcal<1000000007>;
int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i64 n,d,k;
    cin >> n >> d >> k;
    vector<vector<modc>> dp(n + 1,vector<modc> (k + 1,0));
    dp[0][0] = 1;
    rep(i,n) {
        rep(j,k + 1){
            if(j + 1 <= k){
                dp[i + 1][j + 1] += dp[i][j];
                dp[i + 1][min(j + d + 1, k + 1)] -= dp[i][j];
            }
        }
        rep(j,k + 1){
            dp[i + 1][j + 1] += dp[i + 1][j];
        }
    }
    cout << dp[n][k].a << endl;
}
0