結果

問題 No.1102 Remnants
ユーザー simansiman
提出日時 2022-11-03 17:09:38
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 1,257 bytes
コンパイル時間 4,506 ms
コンパイル使用メモリ 107,320 KB
実行使用メモリ 17,024 KB
最終ジャッジ日時 2023-09-25 01:37:37
合計ジャッジ時間 6,016 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 159 ms
14,740 KB
testcase_06 AC 28 ms
5,144 KB
testcase_07 AC 233 ms
17,024 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 9 ms
4,380 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 91 ms
9,396 KB
testcase_15 AC 70 ms
8,080 KB
testcase_16 AC 190 ms
16,036 KB
testcase_17 AC 178 ms
15,360 KB
testcase_18 AC 201 ms
15,200 KB
testcase_19 AC 65 ms
7,276 KB
testcase_20 AC 18 ms
4,540 KB
testcase_21 AC 116 ms
10,444 KB
testcase_22 AC 171 ms
13,408 KB
testcase_23 AC 129 ms
10,972 KB
testcase_24 AC 91 ms
8,908 KB
testcase_25 AC 205 ms
15,472 KB
testcase_26 AC 11 ms
4,376 KB
testcase_27 AC 50 ms
6,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
vector<ll> A;

ll mod_pow(ll x, ll n, ll mod = MOD) {
  ll res = 1;

  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }

    x = x * x % mod;
    n >>= 1;
  }

  return res;
}

ll mod_inverse(ll x, ll mod = MOD) {
  return mod_pow(x, mod - 2, mod);
}

ll build_key(ll n, ll k) {
  return n * 100000000 + k;
}

ll comb(ll n, ll k, map<ll, ll> &memo) {
  memo[k] = 1;
  ll a = 1;
  ll b = 1;
  ll len = n - k;
  for (ll i = 1; i <= len; ++i) {
    a *= (k + i);
    a %= MOD;
    b *= i;
    b %= MOD;
    memo[k + i] = a * mod_inverse(b, MOD) % MOD;
  }

  return b * mod_inverse(a, MOD) % MOD;
}

int main() {
  ll N, K;
  cin >> N >> K;
  A.resize(N);

  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  map<ll, ll> memo;
  ll ans = 0;
  comb(K + N, K, memo);

  for (ll i = 1; i <= N; ++i) {
    ll a = A[i - 1];
    ll b = a * memo[K + i - 1] % MOD;
    ll c = b * memo[N - i + K] % MOD;
    ans += c;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}
0