結果

問題 No.1011 Infinite Stairs
ユーザー kibunakibuna
提出日時 2020-03-20 21:43:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 2,185 bytes
コンパイル時間 1,437 ms
コンパイル使用メモリ 167,244 KB
実行使用メモリ 5,876 KB
最終ジャッジ日時 2023-09-24 10:54:49
合計ジャッジ時間 2,974 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 88 ms
4,872 KB
testcase_04 AC 14 ms
4,380 KB
testcase_05 AC 138 ms
5,876 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 17 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 11 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 60 ms
4,680 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 33 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 14 ms
4,380 KB
testcase_22 AC 27 ms
4,380 KB
testcase_23 AC 17 ms
4,376 KB
testcase_24 AC 18 ms
4,380 KB
testcase_25 AC 29 ms
4,376 KB
testcase_26 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, d, k;
    cin >> n >> d >> k;
    vector<mint> dp(k + 1, 0);
    dp[0] = 1;
    for (int i = 0; i < n; ++i) {
        vector<mint> dpo = dp;
        for (int j = 1; j <= k; ++j) {
            dp[j] += dp[j - 1];
            if (j >= d)
                dp[j] -= dpo[j - d];
        }

        for (int j = k; j > 0; --j) {
            dp[j] = dp[j - 1];
        }
        dp[0] = 0;
    }
    cout << dp[k] << "\n";
    return 0;
}
0