結果

問題 No.1011 Infinite Stairs
ユーザー jjjjjjjtgpptmjjjjjjjjjtgpptmjj
提出日時 2020-03-20 22:21:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 2,960 bytes
コンパイル時間 1,646 ms
コンパイル使用メモリ 167,412 KB
実行使用メモリ 4,556 KB
最終ジャッジ日時 2023-09-24 10:59:49
合計ジャッジ時間 3,252 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 5 ms
4,376 KB
testcase_03 AC 77 ms
4,376 KB
testcase_04 AC 121 ms
4,556 KB
testcase_05 AC 115 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 14 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 47 ms
4,376 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 26 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 18 ms
4,380 KB
testcase_16 AC 79 ms
4,376 KB
testcase_17 AC 85 ms
4,380 KB
testcase_18 AC 34 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 19 ms
4,380 KB
testcase_22 AC 72 ms
4,380 KB
testcase_23 AC 20 ms
4,380 KB
testcase_24 AC 18 ms
4,380 KB
testcase_25 AC 35 ms
4,380 KB
testcase_26 AC 10 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
struct mint {
    long long x;
    mint(long long _x=0):x((_x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint modpow(long long t) const {
        if (!t) return 1;
        mint a = modpow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return modpow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
    friend std::ostream& operator<<(std::ostream& os, const mint& a){
        os << a.x;
        return os;
    }
};

vector<mint> dp;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, d, K;
    cin >> N >> d >> K;

    dp.assign(N * d + d  * 4, 0);
    dp[0] = 1;
    rep(k, N){
        vector<mint> next(N * d + d  * 4, 0);
        rep(i,N * d + 1){
            /*
            rep1(j,d+1){
                next[i+j] += dp[i];
            }*/
            //imosで高速化
            next[i+1] += dp[i];
            next[i+d+1] -= dp[i];
        }
        rep(i,N*d+d){
            next[i+1] += next[i];
        }
        //print(next);
        swap(dp, next);
    }
    cout << dp[K] << endl;
}
0