結果

問題 No.1489 Repeat Cumulative Sum
ユーザー ぷらぷら
提出日時 2021-04-23 22:57:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 201,868 KB
実行使用メモリ 4,892 KB
最終ジャッジ日時 2023-09-17 12:57:28
合計ジャッジ時間 4,825 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 81 ms
4,768 KB
testcase_04 AC 74 ms
4,380 KB
testcase_05 AC 80 ms
4,552 KB
testcase_06 AC 67 ms
4,376 KB
testcase_07 AC 44 ms
4,380 KB
testcase_08 AC 28 ms
4,380 KB
testcase_09 AC 93 ms
4,808 KB
testcase_10 AC 80 ms
4,764 KB
testcase_11 AC 64 ms
4,380 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 58 ms
4,380 KB
testcase_14 AC 99 ms
4,764 KB
testcase_15 AC 96 ms
4,892 KB
testcase_16 AC 49 ms
4,376 KB
testcase_17 AC 55 ms
4,380 KB
testcase_18 AC 42 ms
4,376 KB
testcase_19 AC 28 ms
4,380 KB
testcase_20 AC 36 ms
4,376 KB
testcase_21 AC 66 ms
4,512 KB
testcase_22 AC 7 ms
4,376 KB
testcase_23 AC 23 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 16 ms
4,376 KB
testcase_26 AC 103 ms
4,848 KB
testcase_27 AC 61 ms
4,376 KB
testcase_28 AC 6 ms
4,376 KB
testcase_29 AC 43 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int mod = 1000000007;

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

int main() {
    int N;
    long long M;
    cin >> N >> M;
    vector<int>A(N-1);
    for(int i = 0; i < N-1; i++) {
        cin >> A[i];
    }
    vector<long long>tmp(N);
    long long tmp2 = 1,tmp3 = 1;
    for(int i = 0; i < N; i++) {
        tmp2 *= i+1;
        tmp3 *= (M+i-1)%mod;
        tmp2 %= mod;
        tmp3 %= mod;
        tmp[i] = tmp3*modpow(tmp2,mod-2)%mod;
    }
    vector<long long>sum(N+1);
    for(int i = 0; i < N; i++) {
        sum[i+1] = sum[i]+tmp[i];
        sum[i+1] %= mod;
    }
    long long ans = 0;
    for(int i = 0; i < N-1; i++) {
        ans += A[i];
        ans += A[i]*sum[N-i-1];
        ans %= mod;
    }
    cout << ans << endl;
}
0