結果

問題 No.1102 Remnants
ユーザー DriceDrice
提出日時 2020-07-03 22:50:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,192 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 33,440 KB
実行使用メモリ 789,612 KB
最終ジャッジ日時 2023-10-17 05:52:41
合計ジャッジ時間 8,523 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,308 KB
testcase_01 AC 2 ms
5,308 KB
testcase_02 MLE -
testcase_03 MLE -
testcase_04 AC 2 ms
5,284 KB
testcase_05 AC 18 ms
10,048 KB
testcase_06 AC 11 ms
7,536 KB
testcase_07 MLE -
testcase_08 AC 3 ms
5,304 KB
testcase_09 AC 5 ms
5,348 KB
testcase_10 MLE -
testcase_11 AC 171 ms
222,416 KB
testcase_12 MLE -
testcase_13 AC 3 ms
5,352 KB
testcase_14 AC 13 ms
10,048 KB
testcase_15 AC 26 ms
7,872 KB
testcase_16 AC 65 ms
10,048 KB
testcase_17 AC 61 ms
10,048 KB
testcase_18 AC 64 ms
10,048 KB
testcase_19 AC 23 ms
7,788 KB
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 AC 35 ms
42,224 KB
testcase_27 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
const long long mod = 1e9+7;
long long f[100200005];
long long cc[200005];
long long a[200005];
long long sum[200005];

long long power(long long a,long long b){
    long long res = 1;
    while(b){
        if(b&1) res = res*a%mod;
        a = a*a%mod;
        b /= 2;
    }
    return res;
}

long long inv(long long u){ return power(u,mod-2); }

long long getComb(int n,int m){
    if(m>n || m<0) return 0;
    else{
        long long res = f[n]*inv(f[n-m])%mod*inv(f[m])%mod;
        return res;
    }
}

void preWork(long long k,long long n){
    f[0] = 1;
    for(int i = 1; i <= k+n; i++){
        f[i] = f[i-1]*(long long)i%mod;
    }
    for(long long i = 0; i <= n; i++){
        cc[i] = getComb(k+i-1,i);
    }
    sum[0] = cc[0];
    for(int i = 1; i <= n; i++){
        sum[i] = (sum[i-1]+cc[i])%mod;
    }
}


int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    preWork(k,n);
    long long ans = 0;
    for(int i = 1; i <= n; i++){ 
        long long u;
        scanf("%lld",&u);
        long long cnt = sum[i-1]*sum[n-i]%mod;
        if(k==0) cnt = 1;
        ans += u*cnt%mod;
        if(ans>=mod) ans -= mod;
    }
    printf("%lld\n",ans);
    return 0;
}
0