結果

問題 No.503 配列コレクション
ユーザー dohatsutsudohatsutsu
提出日時 2017-04-21 22:59:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 1,118 ms
コンパイル使用メモリ 145,000 KB
実行使用メモリ 7,672 KB
最終ジャッジ日時 2023-09-27 12:25:33
合計ジャッジ時間 2,168 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 4 ms
4,404 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 11 ms
7,672 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0