結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 106 ms
50,244 KB
testcase_20 AC 6 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 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);
    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[2],0);
    int64_t mod = 1e9+7;
    for(int j=0;j<=cnt;j++){
        beta[1][j]=mod_pow(D,j,mod);
        C[1][j]=1;
    }
    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];
        }
    }
    cout<<(alpha[len&1][cnt]+beta[len&1][cnt])%mod<<endl;
    return 0;
}
0