結果

問題 No.1489 Repeat Cumulative Sum
ユーザー algon_320algon_320
提出日時 2021-04-23 22:54:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 6,084 bytes
コンパイル時間 1,620 ms
コンパイル使用メモリ 172,880 KB
実行使用メモリ 35,228 KB
最終ジャッジ日時 2024-07-04 08:35:56
合計ジャッジ時間 18,082 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 354 ms
34,432 KB
testcase_01 AC 353 ms
34,304 KB
testcase_02 AC 353 ms
34,304 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 357 ms
34,468 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vvb = vector<vb>;
template <class T>
using heap = priority_queue<T, deque<T>, greater<T>>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for (auto &&x : c)
#define rep(i, a, n) for (int i = (int)(a), i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for (int i = (int)(n - 1); i >= a; --i)
#define pb push_back
#define eb emplace_back
#define dump(...)
const signed INF_ = 1001001001;
const long long INF = 1001001001001001001LL;
const int DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
          DY[9] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
template <class C>
int sz(const C &c) {
  return (int)c.size();
}
template <class C, class T>
bool contains(const C &c, const T &v) {
  return c.find(v) != c.end();
}
template <class T>
bool inseg(const T &l, const T &x, const T &r) {
  return l <= x && x < r;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << p.first << " " << p.second;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  return is >> p.first >> p.second;
}
template <class T, class C>
ostream &ostream_container_impl(ostream &os, const C &v) {
  if (v.empty()) return os;
  auto itr = begin(v), prv = prev(end(v));
  while (itr != prv) os << *itr++ << " ";
  return os << *prv;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  return ostream_container_impl<T>(os, v);
}
template <class T>
ostream &operator<<(ostream &os, const deque<T> &v) {
  return ostream_container_impl<T>(os, v);
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &v) {
  return ostream_container_impl<T>(os, v);
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}
template <class T, class U>
bool chmax(T &a, const U &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
void psum(T &c) {
  partial_sum(begin(c), end(c), begin(c));
}
template <class T>
void decrement(T &x) {
  x -= 1;
}
template <class T, class U>
void decrement(pair<T, U> &p) {
  decrement(p.first);
  decrement(p.second);
}
template <class T>
void decrement(vector<T> &v) {
  for (auto &x : v) decrement(x);
}
template <class T>
void increment(T &x) {
  x += 1;
}
template <class T, class U>
void incrment(pair<T, U> &p) {
  increment(p.first);
  increment(p.second);
}
template <class T>
void increment(vector<T> &v) {
  for (auto &x : v) increment(x);
}

#if defined(LOCAL)
void dump_impl(string s) { assert(s.empty()); }
template <class H, class... T>
void dump_impl(string s, const H &head, const T &...tail) {
  int par = 0;
  rep(i, 0, sz(s)) {
    char ch = s[i];
    if (ch == ',' && par == 0) {
      cerr << " = " << head << ",";
      dump_impl(s.substr(i + 1), tail...);
      return;
    } else {
      cerr << ch;
      if (ch == '(') par++;
      if (ch == ')') par--;
    }
  }
}
#ifdef dump
#undef dump
#endif
#define dump(...)                             \
  do {                                        \
    cerr << "\x1b[33;1m";                     \
    dump_impl(#__VA_ARGS__ ",", __VA_ARGS__); \
    cerr << "\x1b[0m" << endl;                \
  } while (0)
#endif

struct before_main_function {
  before_main_function() {
#if defined(LOCAL) && defined(int)
    cerr << "\x1b[7m"
         << "'int' is 'long long'"
         << "\x1b[m" << endl;
#endif
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(15) << fixed;
  }
} before_main_function;
//------------------8<------------------------------------8<--------------------

template <int mod>
class ModInt {
 public:
  ModInt() : v(0) {}
  ModInt(int x) : v((x + mod) % mod) {}
  int value() const { return v; }
  const ModInt operator+(const ModInt &r) const {
    return ModInt(this->v + r.v);
  }
  const ModInt operator-(const ModInt &r) const {
    return ModInt(this->v + mod - r.v);
  }
  const ModInt operator*(const ModInt &r) const {
    return ModInt(this->v * r.v);
  }
  const ModInt operator/(const ModInt &r) const { return (*this * (~r)); }
  const ModInt operator^(int k) const { return ModInt(bpow(this->v, k)); }
  const ModInt operator~() const { return ModInt(bpow(this->v, mod - 2)); }
  bool operator==(const ModInt &r) const { return this->v == r.v; }
  bool operator!=(const ModInt &r) const { return this->v != r.v; }
  ModInt &operator+=(const ModInt &r) { return *this = *this + r; }
  ModInt &operator-=(const ModInt &r) { return *this = *this - r; }
  ModInt &operator*=(const ModInt &r) { return *this = *this * r; }
  ModInt &operator/=(const ModInt &r) { return *this = *this * (~r); }

 private:
  int v;
  int bpow(int a, int b) const {
    int ret = 1;
    while (b > 0) {
      if (b & 1) ret = (ret * a) % mod;
      a = (a * a) % mod;
      b >>= 1;
    }
    return ret;
  }
};
using Mint = ModInt<1000000007>;
using Mvi = vector<Mint>;
using Mvvi = vector<vector<Mint>>;

struct Factorial {
  static constexpr int MAX_N = 2000006;
  vector<Mint> fact, fact_inv;
  Factorial(size_t size = MAX_N) : fact(size), fact_inv(size) {
    fact[0] = fact_inv[0] = 1;
    for (int i = 1; i < MAX_N; ++i) {
      fact[i] = fact[i - 1] * i;
      fact_inv[i] = ~fact[i];
    }
  }
  Mint combination(int N, int R) {
    if (N < R) return 0;
    return fact[N] * fact_inv[N - R] * fact_inv[R];
  }
  static Mint bin_pow(Mint x, int p) {
    if (x.value() == 0) return x;
    Mint prod = 1;
    while (p > 0) {
      if (p & 1) prod *= x;
      x *= x;
      p >>= 1;
    }
    return prod;
  }
} fact;

signed main() {
  int N, M;
  cin >> N >> M;
  vi A(N);
  rep(i, 1, N) cin >> A[i];

  M--;

  Mint ans = 0;
  Mint S = 0;
  int t = 0;
  rrep(i, 1, N) {
    S += fact.combination(M + t, M - 1);
    t += 1;

    ans += (S + 1) * Mint(A[i]);
  }
  cout << ans.value() << endl;
}
0