結果

問題 No.797 Noelちゃんとピラミッド
ユーザー satou_a_mansatou_a_man
提出日時 2019-03-15 21:40:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 826 ms / 2,000 ms
コード長 1,437 bytes
コンパイル時間 2,615 ms
コンパイル使用メモリ 146,528 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2023-09-14 13:18:34
合計ジャッジ時間 57,136 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 809 ms
19,024 KB
testcase_01 AC 807 ms
19,244 KB
testcase_02 AC 798 ms
18,996 KB
testcase_03 AC 821 ms
19,540 KB
testcase_04 AC 826 ms
19,508 KB
testcase_05 AC 823 ms
19,556 KB
testcase_06 AC 816 ms
19,468 KB
testcase_07 AC 815 ms
19,472 KB
testcase_08 AC 825 ms
19,508 KB
testcase_09 AC 823 ms
19,560 KB
testcase_10 AC 819 ms
19,408 KB
testcase_11 AC 823 ms
19,564 KB
testcase_12 AC 821 ms
19,556 KB
testcase_13 AC 823 ms
19,556 KB
testcase_14 AC 816 ms
19,560 KB
testcase_15 AC 826 ms
19,524 KB
testcase_16 AC 812 ms
19,540 KB
testcase_17 AC 821 ms
19,576 KB
testcase_18 AC 814 ms
19,496 KB
testcase_19 AC 813 ms
19,492 KB
testcase_20 AC 818 ms
19,492 KB
testcase_21 AC 819 ms
19,584 KB
testcase_22 AC 819 ms
19,508 KB
testcase_23 AC 813 ms
19,196 KB
testcase_24 AC 801 ms
19,044 KB
testcase_25 AC 818 ms
19,196 KB
testcase_26 AC 812 ms
18,936 KB
testcase_27 AC 816 ms
19,468 KB
testcase_28 AC 809 ms
19,204 KB
testcase_29 AC 808 ms
19,092 KB
testcase_30 AC 819 ms
19,024 KB
testcase_31 AC 823 ms
19,208 KB
testcase_32 AC 806 ms
19,000 KB
testcase_33 AC 824 ms
18,944 KB
testcase_34 AC 811 ms
19,044 KB
testcase_35 AC 818 ms
19,468 KB
testcase_36 AC 798 ms
19,116 KB
testcase_37 AC 810 ms
19,440 KB
testcase_38 AC 821 ms
19,212 KB
testcase_39 AC 813 ms
18,960 KB
testcase_40 AC 808 ms
19,212 KB
testcase_41 AC 808 ms
19,160 KB
testcase_42 AC 811 ms
18,996 KB
testcase_43 AC 806 ms
18,940 KB
testcase_44 AC 808 ms
19,052 KB
testcase_45 AC 809 ms
18,960 KB
testcase_46 AC 819 ms
18,996 KB
testcase_47 AC 806 ms
18,952 KB
testcase_48 AC 809 ms
18,940 KB
testcase_49 AC 805 ms
19,024 KB
testcase_50 AC 807 ms
19,052 KB
testcase_51 AC 813 ms
18,980 KB
testcase_52 AC 809 ms
19,092 KB
testcase_53 AC 810 ms
19,036 KB
testcase_54 AC 805 ms
18,940 KB
testcase_55 AC 805 ms
18,996 KB
testcase_56 AC 808 ms
19,120 KB
testcase_57 AC 801 ms
19,180 KB
testcase_58 AC 799 ms
18,984 KB
testcase_59 AC 799 ms
19,020 KB
testcase_60 AC 807 ms
18,960 KB
testcase_61 AC 808 ms
19,256 KB
testcase_62 AC 795 ms
19,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

ll modpow(ll b, ll e, ll p) {
  if(e==0) return 1;
  if(e%2==0) {
    ll t = modpow(b,e/2,p);
    return (t*t)%p;
  }
  return (b*modpow(b,e-1,p))%p;
}

ll modinv(ll n, ll p) {
  return modpow(n,p-2,p);
}

ll modcomb(ll n, ll k, ll p) { // O(k)
  ll ans=1;
  for(ll i=n; i>=n-k+1; i--) {
    ans*=i;
    ans%=p;
  }
  for(ll i=1; i<=k; i++) {
    ans*=modinv(i,p);
    ans%=p;
  }
  return ans;
}

// O(1) nCk calculation
const ll p = 1e9+7;
const int MX = 1000000;
ll modFact[MX+1];
ll modFactInv[MX+1];
void precalc() {
  modFact[0]=1;
  modFactInv[0]=1;
  repeat(i,1,MX+1) {
    modFact[i]=(modFact[i-1]*i)%p;
    modFactInv[i]=modinv(modFact[i],p);
  }
}

ll fastModComb(ll n, ll k, ll p) {
  // call precalc() first.
  ll ret=modFact[n];
  ret=ret*modFactInv[n-k];
  ret%=p;
  ret=ret*modFactInv[k];
  ret%=p;
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  if(n==1) {
    cout << a[0] << endl;
    return 0;
  }
  precalc();
  ll ans=0;
  rep(i,n) {
    ans+=fastModComb(n-1,i,p)*a[i];
    ans%=p;
  }
  cout <<ans << endl;
  return 0;
}
0