結果

問題 No.1011 Infinite Stairs
ユーザー okok
提出日時 2020-03-20 21:43:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 1,164 bytes
コンパイル時間 827 ms
コンパイル使用メモリ 87,676 KB
実行使用メモリ 5,152 KB
最終ジャッジ日時 2023-09-24 10:55:11
合計ジャッジ時間 2,711 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 4 ms
4,380 KB
testcase_03 AC 121 ms
4,568 KB
testcase_04 AC 22 ms
4,376 KB
testcase_05 AC 184 ms
5,152 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 26 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 16 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 21 ms
4,380 KB
testcase_16 AC 85 ms
4,376 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 50 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 22 ms
4,376 KB
testcase_22 AC 41 ms
4,380 KB
testcase_23 AC 25 ms
4,380 KB
testcase_24 AC 27 ms
4,376 KB
testcase_25 AC 43 ms
4,376 KB
testcase_26 AC 10 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
// } ;
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N, d, K;
	vector<vector<int>> dp;
	
	cin>>N>>d>>K;
	
	dp.resize(2, vector<int>(K+1));
	
	dp[0][0] = 1;
	
	for(int i = 0; i < N; i++){ //cout<<i<<endl;
		vector<int> imos(K+2);
		for(int j = 0; j < K; j++){ //cout<<j<<endl;
			imos[j+1] += dp[i%2][j];
			imos[min(j+d+1,K+1)] -= dp[i%2][j];
			imos[min(j+d+1,K+1)] += MOD;
			imos[min(j+d+1,K+1)] %= MOD;
			// for(int k = 1; k <= d; k++){
				// if(j+k <= K){
					// dp[(i+1)%2][j+k] += dp[i%2][j];
					// dp[(i+1)%2][j+k] %= MOD;
				// }
			// }
		}
		for(int j = 0; j <= K; j++){
			imos[j+1] += imos[j];
			imos[j] %= MOD;
			dp[i%2][j] = 0;
			dp[((i+1)%2)][j] += imos[j];
			dp[((i+1)%2)][j] %= MOD;
		}
	}
	//cout<<"x"<<endl;
	cout<<dp[(N)%2][K]<<endl;
	
	return 0;
}
0