結果

問題 No.503 配列コレクション
ユーザー PulmnPulmn
提出日時 2017-02-17 15:35:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 907 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 63,796 KB
実行使用メモリ 38,132 KB
最終ジャッジ日時 2023-08-29 07:00:48
合計ジャッジ時間 3,409 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,680 KB
testcase_01 AC 4 ms
10,768 KB
testcase_02 AC 4 ms
10,552 KB
testcase_03 AC 4 ms
10,716 KB
testcase_04 AC 5 ms
10,508 KB
testcase_05 AC 5 ms
10,800 KB
testcase_06 AC 5 ms
10,504 KB
testcase_07 AC 4 ms
10,504 KB
testcase_08 AC 6 ms
11,080 KB
testcase_09 AC 5 ms
10,800 KB
testcase_10 AC 7 ms
10,980 KB
testcase_11 AC 24 ms
12,348 KB
testcase_12 AC 129 ms
17,380 KB
testcase_13 AC 5 ms
10,936 KB
testcase_14 AC 73 ms
17,940 KB
testcase_15 AC 121 ms
16,912 KB
testcase_16 AC 4 ms
10,544 KB
testcase_17 AC 4 ms
10,732 KB
testcase_18 AC 152 ms
18,404 KB
testcase_19 AC 106 ms
34,156 KB
testcase_20 AC 192 ms
38,132 KB
testcase_21 AC 5 ms
10,648 KB
testcase_22 AC 19 ms
11,512 KB
testcase_23 AC 5 ms
10,544 KB
testcase_24 AC 4 ms
10,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const ll mod=1e9+7;

ll Pow_mod(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

vl fact(1000000);

ll Fact(ll n){
	if(fact[n]) return fact[n];
	if(!n) return fact[n]=1;
	return fact[n]=Fact(n-1)*n%mod;
}

ll Division_mod(ll n,ll m){
	return n*Pow_mod(m,mod-2)%mod;
}

ll Combination(ll n,ll k){
	return Division_mod(Fact(n),Fact(n-k)*Fact(k)%mod);
}

ll N,K,D;

int main(){
	cin>>N>>K>>D;
	ll num=(N-1)/(K-1),len=N-num*(K-1);
	if(D==1){
		cout<<len<<endl;
		return 0;
	}
	vvl dp(len+1,vl(num+1));
	for(int i=0;i<=num;i++) dp[1][i]=Pow_mod(D,i);
	for(int i=2;i<=len;i++){
		ll x=0,y=0;
		for(int j=0;j<=num;j++){
			x=(x+dp[i-1][j])%mod;
			y=(y*D+Combination(i+j-2,j))%mod;
			dp[i][j]=(x+y)%mod;
		}
	}
	cout<<dp[len][num]<<endl;
}
0