結果

問題 No.535 自然数の収納方法
ユーザー PulmnPulmn
提出日時 2017-02-21 19:18:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 556 ms
コンパイル使用メモリ 66,700 KB
実行使用メモリ 66,120 KB
最終ジャッジ日時 2023-08-28 22:28:52
合計ジャッジ時間 2,538 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 16 ms
13,876 KB
testcase_08 AC 49 ms
39,512 KB
testcase_09 AC 62 ms
48,984 KB
testcase_10 AC 74 ms
58,036 KB
testcase_11 AC 10 ms
9,416 KB
testcase_12 AC 31 ms
25,204 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 23 ms
19,672 KB
testcase_15 AC 78 ms
61,160 KB
testcase_16 AC 49 ms
39,288 KB
testcase_17 AC 83 ms
64,224 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 84 ms
65,688 KB
testcase_20 AC 85 ms
66,060 KB
testcase_21 AC 84 ms
66,064 KB
testcase_22 AC 85 ms
66,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const ll mod=1e9+7;

ll n;

int main(){
	cin>>n;
	vvl dp(n+1,vl(n+1)),DP(n+1,vl(n+1));
	dp[0][0]=1;
	DP[1][1]=1;
	vl a(n);
	for(int i=2;i<n;i++) a[i]=i-2;
	for(int i=1;i<=n;i++){
		vl s=dp[i-1],t=DP[i-1];
		for(int j=1;j<=n;j++){
			(s[j]+=s[j-1])%=mod;
			(t[j]+=t[j-1])%=mod;
		}
		for(int j=1;j<=n;j++){
			dp[i][j]=s[min(n,j+a[i-1])];
			if(i!=1) DP[i][j]=t[min(n,j+a[i-1])];
		}
	}
	ll sum=0;
	for(int i=1;i<=n;i++) (sum+=dp[n][i])%=mod;
	cout<<(sum-DP[n][n]+mod)%mod<<endl;
}
0