結果

問題 No.1102 Remnants
ユーザー Drice
提出日時 2020-07-03 22:50:47
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,192 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 33,408 KB
実行使用メモリ 789,188 KB
最終ジャッジ日時 2024-09-17 04:31:03
合計ジャッジ時間 9,263 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 MLE * 1
other AC * 14 MLE * 11
権限があれば一括ダウンロードができます

ソースコード

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