結果

問題 No.1011 Infinite Stairs
ユーザー shibh308shibh308
提出日時 2020-03-20 21:33:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,180 ms / 2,000 ms
コード長 2,572 bytes
コンパイル時間 2,004 ms
コンパイル使用メモリ 204,776 KB
実行使用メモリ 215,572 KB
最終ジャッジ日時 2023-09-24 10:53:26
合計ジャッジ時間 7,091 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 11 ms
6,040 KB
testcase_03 AC 742 ms
142,900 KB
testcase_04 AC 112 ms
26,672 KB
testcase_05 AC 1,180 ms
215,572 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 7 ms
4,680 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 132 ms
31,684 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 80 ms
20,476 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 104 ms
25,840 KB
testcase_16 AC 498 ms
101,060 KB
testcase_17 AC 30 ms
11,176 KB
testcase_18 AC 291 ms
59,636 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 120 ms
26,120 KB
testcase_22 AC 230 ms
49,056 KB
testcase_23 AC 136 ms
30,644 KB
testcase_24 AC 149 ms
33,492 KB
testcase_25 AC 247 ms
52,424 KB
testcase_26 AC 49 ms
13,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;


template <typename T>
struct BIT{
    vector<T> elm;
    BIT(int n, T init = T()) : elm(n + 1, init){
    }

    // [0, x)
    T sum(int x){
        T val = 0;
        for(; x > 0; x -= x & -x)
            val += elm[x];
        return val;
    }

    // [l, r)
    T sum(int l, int r){
        return sum(r) - sum(l);
    }

    void add(int x, T val){
        for(++x; x < elm.size(); x += x & -x)
            elm[x] += val;
    }
};


signed main(){
    int n, d, k;
    cin >> n >> d >> k;
    // セグ木じゃ通らないんかーい!
    vector<BIT<mint>> dp(n + 1, BIT<mint>(k + 1));
    dp[0].add(0, 1);
    for(int i = 0; i < n; ++i)
        for(int j = 0; j <= k; ++j)
            dp[i + 1].add(j, dp[i].sum(max(0, j - d), j));
    cout << dp.back().sum(k, k + 1) << endl;
    return 0;
}
0