結果

問題 No.1102 Remnants
ユーザー SSlimeSSlime
提出日時 2020-07-04 00:24:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 639 ms / 2,000 ms
コード長 1,041 bytes
コンパイル時間 670 ms
コンパイル使用メモリ 74,844 KB
実行使用メモリ 4,884 KB
最終ジャッジ日時 2023-10-17 06:39:16
合計ジャッジ時間 7,624 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 523 ms
4,348 KB
testcase_03 AC 507 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 66 ms
4,620 KB
testcase_06 AC 17 ms
4,348 KB
testcase_07 AC 639 ms
4,884 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 342 ms
4,348 KB
testcase_11 AC 148 ms
4,348 KB
testcase_12 AC 250 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 44 ms
4,348 KB
testcase_15 AC 34 ms
4,348 KB
testcase_16 AC 86 ms
4,620 KB
testcase_17 AC 82 ms
4,620 KB
testcase_18 AC 101 ms
4,620 KB
testcase_19 AC 35 ms
4,348 KB
testcase_20 AC 184 ms
4,348 KB
testcase_21 AC 483 ms
4,348 KB
testcase_22 AC 573 ms
4,356 KB
testcase_23 AC 466 ms
4,348 KB
testcase_24 AC 340 ms
4,348 KB
testcase_25 AC 325 ms
4,620 KB
testcase_26 AC 33 ms
4,348 KB
testcase_27 AC 412 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

const long long mod = 1000000007;
using ll = long long;

long long modpow(long long n, long long k, long long m)
{
    long long res = 1;
    while (k > 0)
    {
        if (k & 1)
            res = res * n % m;
        k = k >> 1;
        n = n * n % m;
    }
    return res;
}

int main()
{
    ll n, k;
    std::cin >> n >> k;
    std::vector<ll> A(n);
    for (int i = 0; i < n; i++)
        std::cin >> A.at(i);
    ll ans = 0, c = 1, f = 1;
    for (ll i = 1; i < n + k; i++)
    {
        f = (f * i) % mod;
        if (i == k)
            c = (c * modpow(f, mod - 2, mod)) % mod;
        if (i == n - 1)
            c = (c * modpow(f, mod - 2, mod)) % mod;
        if (i == n - 1 + k)
            c = c * f % mod;
    }
    for (ll i = 0; i < n; i++)
    {
        ll a = A.at(i);
        ans = (ans + a * c % mod)%mod;
        c = c * (k + i + 1) % mod * (n - i - 1) % mod;
        c = c * modpow((i + 1) * (n - 1 - i + k) % mod, mod - 2, mod) % mod;
    }
    std::cout << ans << std::endl;
}
0