結果

問題 No.1011 Infinite Stairs
ユーザー Plan8Plan8
提出日時 2020-03-23 12:26:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 2,958 bytes
コンパイル時間 2,428 ms
コンパイル使用メモリ 165,428 KB
実行使用メモリ 215,024 KB
最終ジャッジ日時 2023-09-24 11:08:06
合計ジャッジ時間 3,097 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 3 ms
6,268 KB
testcase_03 AC 77 ms
141,972 KB
testcase_04 AC 18 ms
26,900 KB
testcase_05 AC 114 ms
215,024 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 3 ms
4,952 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 3 ms
4,612 KB
testcase_11 AC 19 ms
31,732 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 13 ms
20,656 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 16 ms
25,948 KB
testcase_16 AC 56 ms
100,588 KB
testcase_17 AC 7 ms
11,496 KB
testcase_18 AC 33 ms
59,156 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 15 ms
26,076 KB
testcase_22 AC 29 ms
49,100 KB
testcase_23 AC 16 ms
30,680 KB
testcase_24 AC 18 ms
32,948 KB
testcase_25 AC 30 ms
51,820 KB
testcase_26 AC 8 ms
13,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

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 pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
    	if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
    	return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(void){
    ll N,d,K; cin >> N >> d >> K;

    mint dp[N+1][K+2];
    dp[0][0] = 1; dp[0][1] = -1;
    mint imos = 0;
    REP(i,N){
        imos = 0;
        REP(j,K){
            imos += dp[i][j];
            if(imos.x > 0){
                dp[i+1][j+1] += imos;
                dp[i+1][min(K+1,j+d+1)] -= imos;
            }
        }
    }
    imos = 0;
    REP(i,K) imos += dp[N][i+1];
    cout << imos.x << en;
    return 0;
}
0