結果

問題 No.1011 Infinite Stairs
ユーザー hiroaki0615hiroaki0615
提出日時 2020-03-20 22:12:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 3,441 bytes
コンパイル時間 627 ms
コンパイル使用メモリ 72,504 KB
実行使用メモリ 215,504 KB
最終ジャッジ日時 2023-09-24 10:58:18
合計ジャッジ時間 2,640 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 5 ms
5,884 KB
testcase_03 AC 154 ms
143,156 KB
testcase_04 AC 27 ms
26,472 KB
testcase_05 AC 226 ms
215,504 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,568 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 33 ms
31,752 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 21 ms
20,524 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 27 ms
25,740 KB
testcase_16 AC 107 ms
100,980 KB
testcase_17 AC 11 ms
11,172 KB
testcase_18 AC 64 ms
59,520 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 26 ms
26,124 KB
testcase_22 AC 52 ms
49,304 KB
testcase_23 AC 32 ms
30,736 KB
testcase_24 AC 35 ms
33,460 KB
testcase_25 AC 56 ms
52,360 KB
testcase_26 AC 12 ms
13,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

template<typename T, long long MOD_VALUE>
class ModInt {
    static constexpr long long MOD = MOD_VALUE;
    private:
        T value_;
    public:
        ModInt() {}
        ModInt(const T& value) {if (value >= 0) {value_ = value % MOD;} else {T k = (MOD - 1 - value) / MOD; value_ = (value + k * MOD) % MOD;}}
        ModInt& operator+=(const ModInt& x)  {value_ += x.value_; if (value_ >= MOD) value_ -= MOD; return *this;}
        friend ModInt& operator+=(const T& x, const ModInt& y) {ModInt res(x); res.value_ += x.value_; if (res.value_ >= MOD) res.value_ -= MOD; return res;}
        ModInt& operator-=(const ModInt& x) {if (value_ < x.value_) value_ += MOD; value_ -= x.value_; return *this;}
        friend ModInt& operator-=(const T& x, const ModInt& y) {ModInt res(x); if (res.value_ < y.value_) res.value_ += MOD; res.value_ -= y.value_; return res;}
        ModInt& operator*=(const ModInt& x) {value_ = (value_ * x.value_) % MOD; return *this;}
        friend ModInt& operator*=(const T& x, const ModInt& y) {ModInt res(x); res.value_ = (res.value_ * y.value_) % MOD; return res;}
        const ModInt operator+(const ModInt& x) const {return ModInt(*this) += x;}
        friend const ModInt operator+(const T& x, const ModInt& y) {return ModInt(x) += y;}
        const ModInt operator-(const ModInt& x) const {return ModInt(*this) -= x;}
        friend const ModInt operator-(const T& x, const ModInt& y) {return ModInt(x) -= y;}
        const ModInt operator*(const ModInt& x) const {return ModInt(*this) *= x;}
        friend const ModInt operator*(const T& x, const ModInt& y) {return ModInt(x) *= y;}
        static ModInt modpow(ModInt x, long long y) {ModInt z = 1; while (y > 0) {if (y & 1) {z *= x;}x *= x; y /= 2;} return z;}
        ModInt& operator/=(const ModInt& x) {return *this *= modpow(x, MOD - 2);}
        const ModInt operator/(const ModInt& x) const {return ModInt(*this) /= x;}
        friend const ModInt operator/(const T& x, const ModInt& y) {return ModInt(x) /= y;}
        ModInt operator++(int) {ModInt tmp(*this); value_ = (value_ + 1 == MOD ? 0 : value_ + 1); return tmp;}
        ModInt operator--(int) {ModInt tmp(*this); value_ = (value_ - 1 < 0 ? MOD - 1 : value_ - 1); return tmp;}
        friend istream& operator>>(istream& stream, ModInt& x) {stream >> x.value_; x.value_ %= MOD; return stream;}
        friend ostream& operator<<(ostream& stream, const ModInt& x) {stream << x.value_; return stream;}
};

using mint = ModInt<ll, 1000000007>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, D, K;
    cin >> N >> D >> K;
    vector<vector<mint>> dp(N + 1, vector<mint>(K + 1, 0));
    dp[0][0] = 1;
    rep(i, 1, N + 1) {
        mint cumsum = 0;
        rep(j, 0, K + 1) {
            dp[i][j] = cumsum;
            cumsum += dp[i - 1][j];
            if (j >= D) {
                cumsum -= dp[i - 1][j - D];
            }
        }
    }
    cout << dp[N][K] << endl;
    return 0;
}
0