結果

問題 No.1011 Infinite Stairs
ユーザー T1610T1610
提出日時 2020-03-20 21:47:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 2,762 bytes
コンパイル時間 1,579 ms
コンパイル使用メモリ 168,164 KB
実行使用メモリ 4,832 KB
最終ジャッジ日時 2023-09-24 10:55:50
合計ジャッジ時間 2,951 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 41 ms
4,376 KB
testcase_04 AC 64 ms
4,832 KB
testcase_05 AC 64 ms
4,732 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 9 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 27 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 15 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 10 ms
4,376 KB
testcase_16 AC 45 ms
4,384 KB
testcase_17 AC 47 ms
4,380 KB
testcase_18 AC 20 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,384 KB
testcase_21 AC 12 ms
4,384 KB
testcase_22 AC 40 ms
4,436 KB
testcase_23 AC 11 ms
4,376 KB
testcase_24 AC 11 ms
4,380 KB
testcase_25 AC 19 ms
4,384 KB
testcase_26 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

template <typename T, typename U> T pow_fast(T x, U n) {
    T ret = (T)1;
    while(n) {
        if(n & (U)1) ret *= x;
        x *= x;
        n >>= 1;
    }
    return ret;
}

template <typename ModType, ModType MOD> struct ModInt {
    ModType val;
    ModInt() : val(0) {}
    ModInt(ModType x) : val(x % MOD) {
        if(val < 0) val += MOD;
    };
    operator ModType() const { return val; }
    ModInt &operator+=(const ModInt &m) {
        val += m.val;
        if(val >= MOD) val -= MOD;
        return *this;
    }
    ModInt &operator-=(const ModInt &m) {
        val -= m.val;
        if(val < 0) val += MOD;
        return *this;
    }
    ModInt &operator*=(const ModInt &m) {
        (val *= m.val) %= MOD;
        return *this;
    }
    ModInt &operator/=(const ModInt &m) {
        *this *= m.inverse();
        return *this;
    }
    ModInt operator+(const ModInt &m) const { return ModInt(*this) += m; }
    ModInt operator-(const ModInt &m) const { return ModInt(*this) -= m; }
    ModInt operator*(const ModInt &m) const { return ModInt(*this) *= m; }
    ModInt operator/(const ModInt &m) const { return ModInt(*this) /= m; }
    ModInt inverse() const { return pow_fast(*this, MOD - 2); }
    ModInt pow(ModType n) const {return pow_fast(*this, n); }

    friend std::ostream &operator<<(std::ostream &os, const ModInt &rhs) {
        os << rhs.val;
        return os;
    }
    friend std::istream &operator>>(std::istream &is, ModInt &rhs) {
        ModType value;
        is >> value;
        rhs = ModInt(value);
        return is;
    }
};

int main(){
    using mint = ModInt<ll, MOD>;
    int n, d, k;
    cin >> n >> d >> k;
    vector<mint> cur(n*d+1);
    cur[0] = 1;
    rep(i, n) {
        vector<mint> nxt(cur.size());
        ll sum = cur[0];
        REP(j, 1, d) {
            nxt[j] = sum;
            sum += cur[j];
        }
        REP(j, d, cur.size()) {
            nxt[j] = sum;
            sum += cur[j];
            sum -= cur[j-d];
        }
        swap(cur, nxt);
    }
    cout << cur[k] << endl;
    return 0;
}
0