結果

問題 No.797 Noelちゃんとピラミッド
ユーザー ei1333333ei1333333
提出日時 2019-03-15 21:28:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 2,688 bytes
コンパイル時間 2,084 ms
コンパイル使用メモリ 203,052 KB
実行使用メモリ 5,384 KB
最終ジャッジ日時 2023-09-14 12:59:00
合計ジャッジ時間 5,004 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 16 ms
4,852 KB
testcase_04 AC 16 ms
4,872 KB
testcase_05 AC 16 ms
4,872 KB
testcase_06 AC 16 ms
4,892 KB
testcase_07 AC 16 ms
4,892 KB
testcase_08 AC 16 ms
4,808 KB
testcase_09 AC 15 ms
4,848 KB
testcase_10 AC 16 ms
4,852 KB
testcase_11 AC 15 ms
5,384 KB
testcase_12 AC 16 ms
4,940 KB
testcase_13 AC 16 ms
4,912 KB
testcase_14 AC 16 ms
4,892 KB
testcase_15 AC 16 ms
4,872 KB
testcase_16 AC 15 ms
4,820 KB
testcase_17 AC 15 ms
4,864 KB
testcase_18 AC 15 ms
4,932 KB
testcase_19 AC 16 ms
4,812 KB
testcase_20 AC 16 ms
4,816 KB
testcase_21 AC 16 ms
4,852 KB
testcase_22 AC 16 ms
4,828 KB
testcase_23 AC 12 ms
4,376 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 10 ms
4,376 KB
testcase_26 AC 10 ms
4,376 KB
testcase_27 AC 16 ms
4,828 KB
testcase_28 AC 14 ms
4,948 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 11 ms
4,380 KB
testcase_32 AC 6 ms
4,380 KB
testcase_33 AC 10 ms
4,376 KB
testcase_34 AC 8 ms
4,376 KB
testcase_35 AC 15 ms
4,908 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 14 ms
4,552 KB
testcase_38 AC 14 ms
4,828 KB
testcase_39 AC 9 ms
4,380 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 4 ms
4,376 KB
testcase_42 AC 10 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 1 ms
4,376 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 1 ms
4,376 KB
testcase_58 AC 1 ms
4,376 KB
testcase_59 AC 2 ms
4,380 KB
testcase_60 AC 1 ms
4,380 KB
testcase_61 AC 2 ms
4,380 KB
testcase_62 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< int mod >
struct Combination {
  vector< int64_t > mfact, rfact;

  Combination(int sz) : mfact(sz + 1), rfact(sz + 1) {
    mfact[0] = 1;
    for(int i = 1; i < mfact.size(); i++) {
      mfact[i] = mfact[i - 1] * i % mod;
    }
    rfact[sz] = inv(mfact[sz]);
    for(int i = sz - 1; i >= 0; i--) {
      rfact[i] = rfact[i + 1] * (i + 1) % mod;
    }
  }

  int64_t fact(int k) const {
    return (mfact[k]);
  }

  int64_t pow(int64_t x, int64_t n) const {
    int64_t ret = 1;
    while(n > 0) {
      if(n & 1) (ret *= x) %= mod;
      (x *= x) %= mod;
      n >>= 1;
    }
    return (ret);
  }

  int64_t inv(int64_t x) const {
    return (pow(x, mod - 2));
  }

  int64_t P(int n, int r) const {
    if(r < 0 || n < r) return (0);
    return (mfact[n] * rfact[n - r] % mod);
  }

  int64_t C(int p, int q) const {
    if(q < 0 || p < q) return (0);
    return (mfact[p] * rfact[q] % mod * rfact[p - q] % mod);
  }

  int64_t H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return (r == 0 ? 1 : C(n + r - 1, r));
  }
};

int main() {
  int N;
  cin >> N;
  vector< int > A(N);
  cin >> A;
  Combination< mod > latte(N);

  int64 add = 0;
  for(int i = N - 1; i >= 0; i--) {
    add += 1LL * latte.C(N - 1, i) * A[i] % mod;
    add %= mod;
  }

  cout << add << endl;
}


0