結果

問題 No.1489 Repeat Cumulative Sum
ユーザー magstamagsta
提出日時 2021-04-05 20:08:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 891 bytes
コンパイル時間 700 ms
コンパイル使用メモリ 82,468 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 07:38:50
合計ジャッジ時間 2,838 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 46 ms
4,380 KB
testcase_04 AC 42 ms
4,376 KB
testcase_05 AC 47 ms
4,376 KB
testcase_06 AC 39 ms
4,376 KB
testcase_07 AC 26 ms
4,384 KB
testcase_08 AC 16 ms
4,376 KB
testcase_09 AC 54 ms
4,380 KB
testcase_10 AC 47 ms
4,376 KB
testcase_11 AC 37 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 34 ms
4,380 KB
testcase_14 AC 57 ms
4,376 KB
testcase_15 AC 55 ms
4,380 KB
testcase_16 AC 28 ms
4,376 KB
testcase_17 AC 32 ms
4,380 KB
testcase_18 AC 25 ms
4,376 KB
testcase_19 AC 16 ms
4,380 KB
testcase_20 AC 20 ms
4,376 KB
testcase_21 AC 39 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 13 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 9 ms
4,380 KB
testcase_26 AC 59 ms
4,380 KB
testcase_27 AC 35 ms
4,376 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 25 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define MOD 1000000007

long long modinv(long long a, long long mod) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}

int main() {
    long long N, M; cin >> N >> M; N--;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    long long ans = 0;
    long long com = 0;
    for (long long i = N - 1; i >= 0; i--) {
        if (i == N - 1) com = M % MOD;
        else com = (com * ((N - i + M - 1) % MOD) % MOD) * modinv(N - i, MOD) % MOD;
        ans += A[i] * com % MOD;
    }
    cout << ans % MOD << endl;
}
0