結果

問題 No.797 Noelちゃんとピラミッド
ユーザー ceni1055ceni1055
提出日時 2019-03-15 21:59:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 605 ms / 2,000 ms
コード長 989 bytes
コンパイル時間 1,495 ms
コンパイル使用メモリ 168,132 KB
実行使用メモリ 8,156 KB
最終ジャッジ日時 2023-09-14 13:34:38
合計ジャッジ時間 23,943 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
7,708 KB
testcase_01 AC 53 ms
7,456 KB
testcase_02 AC 54 ms
7,620 KB
testcase_03 AC 588 ms
8,048 KB
testcase_04 AC 580 ms
8,032 KB
testcase_05 AC 589 ms
8,128 KB
testcase_06 AC 576 ms
7,880 KB
testcase_07 AC 593 ms
8,152 KB
testcase_08 AC 582 ms
8,140 KB
testcase_09 AC 576 ms
7,884 KB
testcase_10 AC 588 ms
8,088 KB
testcase_11 AC 582 ms
7,948 KB
testcase_12 AC 589 ms
8,000 KB
testcase_13 AC 590 ms
8,000 KB
testcase_14 AC 582 ms
8,036 KB
testcase_15 AC 577 ms
8,040 KB
testcase_16 AC 576 ms
7,992 KB
testcase_17 AC 591 ms
7,956 KB
testcase_18 AC 579 ms
7,996 KB
testcase_19 AC 580 ms
8,088 KB
testcase_20 AC 592 ms
8,080 KB
testcase_21 AC 579 ms
8,012 KB
testcase_22 AC 580 ms
8,076 KB
testcase_23 AC 437 ms
8,064 KB
testcase_24 AC 170 ms
7,764 KB
testcase_25 AC 375 ms
7,996 KB
testcase_26 AC 354 ms
7,996 KB
testcase_27 AC 561 ms
8,076 KB
testcase_28 AC 519 ms
8,012 KB
testcase_29 AC 123 ms
7,828 KB
testcase_30 AC 164 ms
7,636 KB
testcase_31 AC 432 ms
8,140 KB
testcase_32 AC 210 ms
7,512 KB
testcase_33 AC 367 ms
7,968 KB
testcase_34 AC 273 ms
7,940 KB
testcase_35 AC 605 ms
8,104 KB
testcase_36 AC 111 ms
7,720 KB
testcase_37 AC 521 ms
8,156 KB
testcase_38 AC 537 ms
8,064 KB
testcase_39 AC 365 ms
8,144 KB
testcase_40 AC 109 ms
7,684 KB
testcase_41 AC 137 ms
7,724 KB
testcase_42 AC 346 ms
8,016 KB
testcase_43 AC 56 ms
7,524 KB
testcase_44 AC 55 ms
7,620 KB
testcase_45 AC 56 ms
7,516 KB
testcase_46 AC 56 ms
7,508 KB
testcase_47 AC 55 ms
7,556 KB
testcase_48 AC 55 ms
7,624 KB
testcase_49 AC 55 ms
7,448 KB
testcase_50 AC 55 ms
7,560 KB
testcase_51 AC 55 ms
7,552 KB
testcase_52 AC 56 ms
7,508 KB
testcase_53 AC 55 ms
7,624 KB
testcase_54 AC 56 ms
7,616 KB
testcase_55 AC 56 ms
7,752 KB
testcase_56 AC 55 ms
7,444 KB
testcase_57 AC 55 ms
7,436 KB
testcase_58 AC 55 ms
7,488 KB
testcase_59 AC 56 ms
7,800 KB
testcase_60 AC 55 ms
7,628 KB
testcase_61 AC 55 ms
7,572 KB
testcase_62 AC 56 ms
7,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

const int MOD = 1e9 + 7;

vector<long long> fac(300001), ifac(300001);

long long mpow(long long x, long long n)
{
  long long ans = 1;
  while (n != 0)
  {
    if (n & 1)
      ans = ans * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return ans;
}

long long comb(long long a, long long b)
{
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  long long tmp = ifac[a - b] * ifac[b] % MOD;
  return tmp * fac[a] % MOD;
}

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  fac[0] = 1;
  ifac[0] = 1;
  for (long long i = 0; i < 300000; i++)
  {
    fac[i + 1] = fac[i] * (i + 1) % MOD;
    ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
  }
  long long ans = 0;
  for (int i = 0; i < N; i++)
  {
    ans = (ans + comb(N - 1, i) * a[i]) % MOD;
    cerr << i << " " << comb(N - 1, i) << endl;
  }
  cout << ans << endl;

  return 0;
}
0