結果

問題 No.1011 Infinite Stairs
ユーザー oevloevl
提出日時 2020-04-19 11:09:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,292 ms / 2,000 ms
コード長 3,808 bytes
コンパイル時間 2,026 ms
コンパイル使用メモリ 202,668 KB
実行使用メモリ 215,496 KB
最終ジャッジ日時 2023-09-24 11:13:34
合計ジャッジ時間 19,955 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
6,492 KB
testcase_01 AC 26 ms
8,876 KB
testcase_02 AC 1,013 ms
184,604 KB
testcase_03 AC 1,206 ms
205,068 KB
testcase_04 AC 1,292 ms
215,492 KB
testcase_05 AC 1,284 ms
215,496 KB
testcase_06 AC 7 ms
5,180 KB
testcase_07 AC 666 ms
116,440 KB
testcase_08 AC 7 ms
5,136 KB
testcase_09 AC 19 ms
7,244 KB
testcase_10 AC 302 ms
53,868 KB
testcase_11 AC 1,134 ms
193,896 KB
testcase_12 AC 288 ms
53,000 KB
testcase_13 AC 618 ms
105,748 KB
testcase_14 AC 376 ms
67,700 KB
testcase_15 AC 882 ms
156,556 KB
testcase_16 AC 1,112 ms
192,312 KB
testcase_17 AC 1,156 ms
203,696 KB
testcase_18 AC 871 ms
149,544 KB
testcase_19 AC 218 ms
41,040 KB
testcase_20 AC 214 ms
40,332 KB
testcase_21 AC 547 ms
97,264 KB
testcase_22 AC 999 ms
172,124 KB
testcase_23 AC 515 ms
88,296 KB
testcase_24 AC 670 ms
116,444 KB
testcase_25 AC 979 ms
173,260 KB
testcase_26 AC 388 ms
68,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<int64_t MOD> class ModInt {
public:
    int64_t x;
    constexpr ModInt() : x(0) {}
    constexpr ModInt(int64_t v) : x((v % MOD + MOD) % MOD) {}
    constexpr ModInt operator - () const noexcept { return x ? MOD - x : 0;}
    constexpr ModInt operator + (const ModInt a) const noexcept { return ModInt(*this) += a;}
    constexpr ModInt operator - (const ModInt a) const noexcept { return ModInt(*this) -= a;}
    constexpr ModInt operator * (const ModInt a) const noexcept { return ModInt(*this) *= a;}
    constexpr ModInt operator / (const ModInt a) const noexcept { return ModInt(*this) /= a;}
    constexpr ModInt operator / (const int64_t a) const noexcept { return ModInt(*this) /= a;}
    constexpr ModInt operator += (const ModInt a) noexcept {
        x += a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }
    constexpr ModInt operator += (const int64_t a) noexcept {
        auto hs = ModInt<MOD>(a);
        (*this) += hs;
        return *this;
    }
    constexpr ModInt operator -= (const ModInt a) noexcept {
        if (x < a.x) x += MOD;
        x -= a.x;
        return *this;
    }
    constexpr ModInt operator -= (const int64_t a) noexcept {
        auto hs = ModInt<MOD>(a);
        (*this) -= hs;
        return *this;
    }
    constexpr ModInt operator *= (const ModInt a) noexcept {
        x = x * a.x % MOD;
        return *this;
    }
    constexpr ModInt operator *= (const int64_t a) noexcept {
        auto hs = ModInt<MOD>(a);
        (*this) *= hs;
        return *this;
    }
    constexpr ModInt &operator /= (ModInt a) noexcept {
        int64_t exp = MOD - 2;
        while (exp > 0) {
            if (exp & 1ul) *this *= a;
            a *= a;
            exp >>= 1ul;
        }
        return *this;
    }
    constexpr ModInt &operator /= (int64_t a) noexcept {
        auto hs = ModInt<MOD>(a);
        (*this) /= hs;
        return *this;
    }
    constexpr ModInt &operator ++ () noexcept {
        if (++x >= MOD) x -= MOD;
        return *this;
    }
    constexpr ModInt &operator -- () noexcept {
        if (x-- == 0) x += MOD;
        return *this;
    }
    constexpr bool operator < (const ModInt a) const noexcept { return x < a.x;}
    constexpr bool operator == (const ModInt a) const noexcept { return this->x == a.x;}
    constexpr bool operator != (const ModInt a) const noexcept { return !(*this == a);}
    friend istream &operator >> (istream &in, ModInt &m) {
        in >> m.x;
        if (m.x < 0) m.x += MOD;
        m.x %= MOD;
        return in;
    }
    friend ostream &operator << (ostream &out, const ModInt &p) { return out << p.x;}
    constexpr ModInt pow(int64_t p) const {
        ModInt ret(1);
        ModInt mul(x);
        while (p > 0) {
            if (p & 1ul) ret *= mul;
            mul *= mul;
            p >>= 1ul;
        }
        return ret;
    }
};

const int64_t MOD = 1000000007LL;
using mint = ModInt<MOD>;

template<class T> class Fenwick {
private:
    vector<T> dat;
    int n;
public:
    Fenwick(int _n) : dat(_n + 1), n(_n) {}
    // sum of [1, i]
    T sum(int i) {
        T s = 0;
        while(i > 0) s += dat[i], i -= i & -i;
        return s;
    }
    // sum of [l, r]
    T sum(int l, int r) {
        return l > r ? 0 : sum(r) - sum(l - 1);
    }
    void add(int i, T x) {
        while(i <= n) dat[i] += x, i += i & -i;
    }
};

int main() {
    int N, d, K;
    cin >> N >> d >> K;
    const int M = 90009;
    using FEN = Fenwick<mint>;
    vector<FEN> fen(N + 1, FEN(M + 2));
    fen[0].add(1, 1);
    for(int i = 1; i <= N; ++i) {
        for(int j = 1; j <= M; ++j) {
            fen[i].add(j + 1, fen[i - 1].sum(max(0, j - d) + 1, j));
        }
    }
    cout << fen[N].sum(K + 1, K + 1) << '\n';
    return 0;
}
0