結果

問題 No.503 配列コレクション
ユーザー PulmnPulmn
提出日時 2017-02-17 12:03:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 710 ms
コンパイル使用メモリ 63,532 KB
実行使用メモリ 38,280 KB
最終ジャッジ日時 2023-08-29 06:33:55
合計ジャッジ時間 2,872 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,628 KB
testcase_01 AC 4 ms
10,788 KB
testcase_02 AC 4 ms
10,684 KB
testcase_03 AC 6 ms
10,564 KB
testcase_04 AC 5 ms
10,648 KB
testcase_05 AC 4 ms
10,728 KB
testcase_06 AC 5 ms
10,532 KB
testcase_07 AC 5 ms
10,788 KB
testcase_08 AC 6 ms
11,108 KB
testcase_09 AC 5 ms
10,544 KB
testcase_10 AC 8 ms
11,060 KB
testcase_11 AC 21 ms
12,392 KB
testcase_12 AC 129 ms
17,180 KB
testcase_13 AC 5 ms
11,032 KB
testcase_14 AC 56 ms
17,904 KB
testcase_15 AC 124 ms
16,876 KB
testcase_16 AC 5 ms
10,748 KB
testcase_17 AC 6 ms
10,632 KB
testcase_18 AC 154 ms
18,440 KB
testcase_19 AC 108 ms
34,156 KB
testcase_20 AC 120 ms
38,280 KB
testcase_21 AC 4 ms
10,652 KB
testcase_22 AC 19 ms
11,492 KB
testcase_23 AC 5 ms
10,784 KB
testcase_24 AC 4 ms
10,856 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=i-1,y=1;
		dp[i][0]=i;
		for(int j=1;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