結果

問題 No.1102 Remnants
ユーザー yataro800
提出日時 2023-04-06 21:27:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 1,381 bytes
コンパイル時間 4,164 ms
コンパイル使用メモリ 235,704 KB
実行使用メモリ 32,896 KB
最終ジャッジ日時 2024-10-02 18:18:24
合計ジャッジ時間 7,940 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <math.h>

#include <algorithm>
#include <array>
#include <atcoder/all>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using namespace atcoder;

using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

using mint = modint1000000007;
map<P_ll, mint> mp;
mint nCr(ll n, ll r) {
  P_ll key = {n, r};
  if (mp.count(key)) return mp[key];

  if (r == 0 or r == n) {
    mint mt = 1;
    return mt;
  }
  if (r == 1 or r == n - 1) {
    mint mt = n;
    return mt;
  }
  // return mp[key] = nCr(n,r-1) * (n-r+1) / r;
  return mp[key] = nCr(n - 1, r) * n / (n - r);
}

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  modint1000000007 ans = 0;
  for (int i = 0; i < N; i++) {
    ans += nCr(K + i, K) * nCr(N - i + K - 1, K) * A[i];
  }
  cout << ans.val() << endl;

  return 0;
}
0