結果

問題 No.1102 Remnants
ユーザー DriceDrice
提出日時 2020-07-03 23:05:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,438 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 33,328 KB
実行使用メモリ 9,484 KB
最終ジャッジ日時 2023-10-17 06:06:59
合計ジャッジ時間 2,097 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,284 KB
testcase_01 AC 3 ms
5,284 KB
testcase_02 AC 2 ms
5,284 KB
testcase_03 AC 2 ms
5,284 KB
testcase_04 AC 2 ms
5,284 KB
testcase_05 AC 44 ms
9,224 KB
testcase_06 AC 11 ms
5,616 KB
testcase_07 AC 59 ms
9,484 KB
testcase_08 AC 3 ms
5,304 KB
testcase_09 AC 4 ms
5,348 KB
testcase_10 AC 2 ms
5,292 KB
testcase_11 AC 4 ms
5,328 KB
testcase_12 AC 5 ms
5,356 KB
testcase_13 AC 5 ms
5,352 KB
testcase_14 AC 27 ms
8,636 KB
testcase_15 AC 22 ms
6,288 KB
testcase_16 AC 52 ms
9,352 KB
testcase_17 AC 49 ms
9,268 KB
testcase_18 AC 53 ms
9,276 KB
testcase_19 AC 19 ms
6,120 KB
testcase_20 AC 8 ms
5,480 KB
testcase_21 AC 32 ms
8,728 KB
testcase_22 AC 45 ms
9,076 KB
testcase_23 AC 35 ms
8,808 KB
testcase_24 AC 25 ms
6,472 KB
testcase_25 AC 53 ms
9,300 KB
testcase_26 AC 5 ms
5,360 KB
testcase_27 AC 15 ms
5,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
const long long mod = 1e9+7;
long long f[200005];
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 <= n; i++){
        f[i] = f[i-1]*(long long)i%mod;
    }
    long long fac = 1;
    for(long long i = k-1; i >= k; i--) fac = fac*i%mod;
    cc[0] = fac; 
    for(long long i = 1; i <= n; i++){
        fac = fac*(long long)(k+i-1)%mod;
        cc[i] = fac*inv(f[i])%mod;
    }
    sum[0] = cc[0];
    for(int i = 1; i <= n; i++){
        sum[i] = (sum[i-1]+cc[i])%mod;
    }
}
/*
5 100000000
cc[0] = 1
cc[1] = 100000000
cc[2] = 15000000
cc[3] = 6500000
cc[4] = 3737500
cc[5] = 2466750
*/

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