結果

問題 No.503 配列コレクション
ユーザー latte0119latte0119
提出日時 2017-04-07 22:42:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,443 bytes
コンパイル時間 2,409 ms
コンパイル使用メモリ 145,148 KB
実行使用メモリ 55,680 KB
最終ジャッジ日時 2023-09-23 02:14:43
合計ジャッジ時間 4,625 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
55,596 KB
testcase_01 AC 58 ms
55,436 KB
testcase_02 AC 58 ms
55,680 KB
testcase_03 AC 60 ms
55,436 KB
testcase_04 AC 58 ms
55,456 KB
testcase_05 AC 58 ms
55,392 KB
testcase_06 AC 59 ms
55,488 KB
testcase_07 AC 59 ms
55,460 KB
testcase_08 AC 57 ms
55,600 KB
testcase_09 AC 57 ms
55,400 KB
testcase_10 AC 57 ms
55,476 KB
testcase_11 AC 57 ms
55,460 KB
testcase_12 AC 57 ms
55,452 KB
testcase_13 AC 57 ms
55,472 KB
testcase_14 AC 56 ms
55,500 KB
testcase_15 AC 57 ms
55,444 KB
testcase_16 AC 56 ms
55,440 KB
testcase_17 AC 57 ms
55,392 KB
testcase_18 AC 57 ms
55,388 KB
testcase_19 AC 65 ms
55,520 KB
testcase_20 AC 56 ms
55,500 KB
testcase_21 AC 57 ms
55,428 KB
testcase_22 AC 57 ms
55,476 KB
testcase_23 AC 56 ms
55,464 KB
testcase_24 AC 57 ms
55,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;


int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}
int fact[3333333];
int inv[3333333];

int C(int n,int k){
    return fact[n]*inv[k]%mod*inv[n-k]%mod;
}

int H(int n,int k){
    if(n==0&&k==0)return 1;
    return C(k+n-1,n-1);
}

signed main(){
    fact[0]=1;
    for(int i=1;i<3333333;i++)fact[i]=fact[i-1]*i%mod;
    inv[3333333-1]=mpow(fact[3333333-1],mod-2);
    for(int i=3333333-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;


    int N,K,D;

    cin>>N>>K>>D;

    int tmp=0;
    int n=N;
    while(n>=K){
        n-=K-1;
        tmp++;
    }

    if(D==1){
        cout<<n<<endl;
        return 0;
    }

    int ans=0;
    int po=1;
    for(int i=0;i<=tmp;i++){
        ans=(ans+H(n-1,tmp-i)*po)%mod;
        po=po*D%mod;
    }

    cout<<ans*n%mod<<endl;
    return 0;
}
0