結果

問題 No.1102 Remnants
ユーザー chocono2230chocono2230
提出日時 2020-07-04 11:26:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 2,118 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 170,460 KB
実行使用メモリ 6,504 KB
最終ジャッジ日時 2023-10-19 00:03:35
合計ジャッジ時間 4,290 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 77 ms
5,976 KB
testcase_06 AC 19 ms
4,348 KB
testcase_07 AC 129 ms
6,504 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 7 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 49 ms
4,656 KB
testcase_15 AC 38 ms
4,392 KB
testcase_16 AC 97 ms
6,240 KB
testcase_17 AC 91 ms
5,976 KB
testcase_18 AC 112 ms
5,976 KB
testcase_19 AC 39 ms
4,392 KB
testcase_20 AC 13 ms
4,348 KB
testcase_21 AC 68 ms
4,920 KB
testcase_22 AC 96 ms
5,712 KB
testcase_23 AC 74 ms
5,184 KB
testcase_24 AC 53 ms
4,656 KB
testcase_25 AC 114 ms
5,976 KB
testcase_26 AC 8 ms
4,348 KB
testcase_27 AC 31 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

void fc(vector<mint> &comb, int n, int k){
  comb.at(0) = 1;
  rep2(i, 1, n){
    comb.at(i) = comb.at(i-1) * (k+i) / i;
  }
}

int main(){
  int n, k;
  cin >> n >> k;
  vector<mint> a(n);
  rep(i, n){
    int in;
    cin >> in;
    a.at(i) = in;
  }
  vector<mint> comb(n);
  fc(comb, n, k);
  mint ans = 0;
  rep(i, n){
    mint add = a.at(i);
    add *= comb.at(i) * comb.at(n-1-i);
    ans += add;
  }
  cout << ans.x << endl;
  return 0;
}
0