結果
| 問題 |
No.503 配列コレクション
|
| コンテスト | |
| ユーザー |
dohatsutsu
|
| 提出日時 | 2017-04-21 22:59:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 14 ms / 2,000 ms |
| コード長 | 1,022 bytes |
| コンパイル時間 | 1,886 ms |
| コンパイル使用メモリ | 158,440 KB |
| 実行使用メモリ | 7,296 KB |
| 最終ジャッジ日時 | 2024-07-20 06:32:45 |
| 合計ジャッジ時間 | 2,438 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7; // 1e9+9
ll add(ll x,ll y){return (x+y)%mod;}
ll mul(ll x,ll y){return (x*y)%mod;}
ll mypow(ll x,ll y){
ll v=1;
for(;y;x=mul(x,x),y>>=1)
if(y&1)v=mul(v,x);
return v;
}
ll divi(ll x,ll y){return mul(x,mypow(y,mod-2));}
ll fact[10000000]={}, factc=0;
ll Fact(ll x){
fact[0]=1;
while( factc < x ){
factc++;
fact[factc]=mul( fact[factc-1] , factc );
}
return fact[x];
}
ll nCr(ll n,ll r){
return divi( Fact(n) , mul( Fact(n-r) , Fact(r) ) );
}
ll nHr(ll n,ll r){
return nCr( n+r-1 , n );
}
ll N,K,D;
int main(){
cin>>N>>K>>D;
ll cc=0;
while(N>=K){
N-=(K-1);
cc++;
}
if(D==1){
cout<<N<<endl;
return 0;
}
if(N==1){
cout<< mypow(D,cc) <<endl;
return 0;
}
ll ans=0,B=1;
for(ll i=0;i<=cc;i++){
ll tu=(cc-i);
ans=add(ans, mul( nHr(tu,N-1) , B ) );
B=mul(B,D);
}
if(N==1){
cout<<"!!"<<endl;
}
cout<< mul(ans,N) <<endl;
return 0;
}
dohatsutsu