結果

問題 No.1011 Infinite Stairs
ユーザー goto_isyukugoto_isyuku
提出日時 2020-03-20 21:59:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 418 ms / 2,000 ms
コード長 2,238 bytes
コンパイル時間 1,575 ms
コンパイル使用メモリ 169,880 KB
実行使用メモリ 428,416 KB
最終ジャッジ日時 2023-09-24 10:57:45
合計ジャッジ時間 6,848 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 305 ms
313,748 KB
testcase_03 AC 374 ms
386,384 KB
testcase_04 AC 418 ms
428,416 KB
testcase_05 AC 412 ms
428,392 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 121 ms
123,392 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 25 ms
27,200 KB
testcase_11 AC 336 ms
345,820 KB
testcase_12 AC 24 ms
26,028 KB
testcase_13 AC 100 ms
101,848 KB
testcase_14 AC 41 ms
42,184 KB
testcase_15 AC 221 ms
224,584 KB
testcase_16 AC 329 ms
339,824 KB
testcase_17 AC 367 ms
381,596 KB
testcase_18 AC 202 ms
204,492 KB
testcase_19 AC 15 ms
16,164 KB
testcase_20 AC 14 ms
15,688 KB
testcase_21 AC 84 ms
86,216 KB
testcase_22 AC 267 ms
270,756 KB
testcase_23 AC 67 ms
70,968 KB
testcase_24 AC 118 ms
123,404 KB
testcase_25 AC 268 ms
276,032 KB
testcase_26 AC 42 ms
42,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

class ModInt{
public:
    long long n;
    int p;

    ModInt(){
    }

    //値と割る値を受け取って、オブジェクトを返す
    ModInt(long long _n, int _p){
        p = _p;
        n = _n % _p;

        //負の値を受け取ったときには正の値に戻す
        if(n < 0){
            n += p;
        }
    }

    ModInt operator+(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n += a.n;

        if(tmp.n > tmp.p){
            tmp.n -= tmp.p;
        }
        
        return tmp;
    }

    ModInt operator-(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n -= a.n;

        if(tmp.n < 0){
            tmp.n += tmp.p;
        }

        return tmp;
    }

    ModInt operator*(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n = (tmp.n * a.n) % tmp.p;

        return tmp;
    }

    int modpow(int b, int k){
        if(k == 0){
            return 1;
        }else if(k % 2 == 1){
            long long tmp = b;
            tmp = tmp * modpow(b, k - 1) % p;
            
            return tmp;
        }else{
            long long tmp = modpow(b, k / 2);
            return tmp * tmp % p;
        }
    }

    int modinv(int b){
        return modpow(b, p - 2);
    }

    ModInt operator/(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n = tmp.n * modinv(a.n) % tmp.p;
        return tmp;
    }
};

int main(){

    int n,d,k;
    cin >> n >> d >> k;

    vector<vector<ModInt>> dp(n + 1, vector<ModInt>(300 * n + 2, ModInt(0, MODN)));

    dp[0][0] = ModInt(1, MODN);

    for(int i = 0; i < n; i++){
        for(int j = 0; j < 300 * i + 1; j++){

            dp[i + 1][j + 1] = dp[i + 1][j + 1] + dp[i][j];
            dp[i + 1][j + d + 1] = dp[i + 1][j + d + 1] - dp[i][j];
        }

        for(int j = 1; j <= 300 * n + 1; j++){
            dp[i + 1][j] = dp[i + 1][j] + dp[i + 1][j - 1];
        }
    }

    cout << dp[n][k].n << endl;
}
0