結果

問題 No.503 配列コレクション
ユーザー confconf
提出日時 2017-03-18 15:42:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,244 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 66,308 KB
実行使用メモリ 50,332 KB
最終ジャッジ日時 2023-09-18 02:24:39
合計ジャッジ時間 1,597 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

int64_t mod_pow(int64_t a, int64_t e, int64_t p){
    int64_t res = 1;
    for(;e>0;e>>=1){
        if(e&1)res=(res*a)%p;
        a=(a*a)%p;
    }
    return res;
}

int main(){
    int64_t N,K,D;
    cin>>N>>K>>D;
    int cnt = N/(K-1)-(N%(K-1)==0);
    // int cnt = (N-1)/(K-1);
    int len = N-cnt*(K-1);
    // cout<<cnt<<' '<<len<<endl;
    if(D==1){
        cout<<len<<endl;
        return 0;
    }
    int64_t alpha[2][cnt+1],beta[2][cnt+1],C[2][cnt+1];
    
    fill(alpha[0],alpha[2],0);
    fill(beta[0],beta[2],0);
    fill(C[0],C[1],0);
    fill(C[1],C[2],1);
    int64_t mod = 1e9+7;
    beta[1][0]=1;
    for(int j=0;j<cnt;j++){
        beta[1][j+1]=beta[1][j]*D%mod;
    }
    if(len>=2)
    for(int i=2;i<=len;i++){
        alpha[i&1][0]=i-1;
        beta[i&1][0]=1;
        C[i&1][0]=1;
        for(int j=0;j<cnt;j++){
            alpha[i&1][j+1]=(alpha[i&1][j]+alpha[i&1^1][j+1]+beta[i&1^1][j+1])%mod;
            //beta[i&1][j+1]=(mod_comb(i+j-1,i-2,mod)+D*beta[i&1][j])%mod;
            beta[i&1][j+1]=(C[i&1^1][j+1]+D*beta[i&1][j])%mod;
            C[i&1][j+1]=(C[i&1][j]+C[i&1^1][j+1])%mod;
        }
    }
    cout<<(alpha[len&1][cnt]+beta[len&1][cnt])%mod<<endl;
    return 0;
}
0