結果

問題 No.503 配列コレクション
ユーザー PulmnPulmn
提出日時 2017-02-17 11:32:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 921 bytes
コンパイル時間 1,364 ms
コンパイル使用メモリ 63,452 KB
実行使用メモリ 30,536 KB
最終ジャッジ日時 2023-08-29 06:26:34
合計ジャッジ時間 3,326 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 123 ms
9,848 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 118 ms
9,060 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 148 ms
10,776 KB
testcase_19 AC 102 ms
26,360 KB
testcase_20 WA -
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 16 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 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(10000);

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