結果

問題 No.1489 Repeat Cumulative Sum
ユーザー t33ft33f
提出日時 2021-04-23 23:40:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 580 ms / 2,000 ms
コード長 750 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 69,048 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 13:13:57
合計ジャッジ時間 10,315 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 454 ms
4,376 KB
testcase_04 AC 416 ms
4,380 KB
testcase_05 AC 458 ms
4,376 KB
testcase_06 AC 374 ms
4,380 KB
testcase_07 AC 243 ms
4,376 KB
testcase_08 AC 152 ms
4,380 KB
testcase_09 AC 527 ms
4,376 KB
testcase_10 AC 458 ms
4,380 KB
testcase_11 AC 363 ms
4,376 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 AC 333 ms
4,380 KB
testcase_14 AC 567 ms
4,380 KB
testcase_15 AC 552 ms
4,376 KB
testcase_16 AC 274 ms
4,380 KB
testcase_17 AC 308 ms
4,380 KB
testcase_18 AC 240 ms
4,376 KB
testcase_19 AC 145 ms
4,380 KB
testcase_20 AC 195 ms
4,380 KB
testcase_21 AC 375 ms
4,376 KB
testcase_22 AC 31 ms
4,376 KB
testcase_23 AC 123 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 82 ms
4,376 KB
testcase_26 AC 580 ms
4,376 KB
testcase_27 AC 345 ms
4,376 KB
testcase_28 AC 27 ms
4,380 KB
testcase_29 AC 232 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

constexpr int M = 1000000007;

long long modinv(long long a, long long m) {
    long long x = m, y = a, p = 1, q = 0, r = 0, s = 1;
    while (y != 0) {
        long long u = x / y;
        long long x0 = y; y = x - y * u; x = x0;
        long long r0 = p - r * u, s0 = q - s * u;
        p = r; r = r0; q = s; s = s0;
    }
    return q < 0 ? q + m : q;
}

int main() {
    long long n, m; cin >> n >> m;
    int a[n-1]; for (int i = 0; i < n-1; i++) cin >> a[i];
    long long ans = 0, c = m % M;
    for (int i = n-2; i >= 0; i--) {
        ans += a[i] * c % M;
        cerr << ans << ' ' << c <<  endl;
        c = (n + m - i - 1) % M * modinv(n - i, M) % M * c % M;
    }
    cout << ans % M << endl;
}
0