結果

問題 No.797 Noelちゃんとピラミッド
ユーザー どらえマン
提出日時 2019-03-15 22:30:56
言語 C++14
(gcc 8.2.0)
結果
AC  
実行時間 102 ms
コード長 1,000 Byte
コンパイル時間 1,338 ms
使用メモリ 8,916 KB
最終ジャッジ日時 2019-05-07 13:27:20

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
001sample.txt AC 2 ms
6,872 KB
002sample.txt AC 3 ms
6,868 KB
003sample.txt AC 3 ms
6,872 KB
LEARGE_case1.txt AC 100 ms
6,868 KB
LEARGE_case2.txt AC 99 ms
6,868 KB
LEARGE_case3.txt AC 99 ms
6,872 KB
LEARGE_case4.txt AC 100 ms
6,868 KB
LEARGE_case5.txt AC 99 ms
6,872 KB
LEARGE_case6.txt AC 99 ms
6,872 KB
LEARGE_case7.txt AC 99 ms
6,868 KB
LEARGE_case8.txt AC 102 ms
8,916 KB
LEARGE_case9.txt AC 100 ms
6,868 KB
LEARGE_case10.txt AC 101 ms
6,868 KB
LEARGE_case11.txt AC 100 ms
6,872 KB
LEARGE_case12.txt AC 100 ms
6,868 KB
LEARGE_case13.txt AC 100 ms
6,868 KB
LEARGE_case14.txt AC 100 ms
6,868 KB
LEARGE_case15.txt AC 100 ms
6,872 KB
LEARGE_case16.txt AC 100 ms
6,868 KB
LEARGE_case17.txt AC 100 ms
6,872 KB
LEARGE_case18.txt AC 99 ms
6,868 KB
LEARGE_case19.txt AC 101 ms
6,872 KB
LEARGE_case20.txt AC 100 ms
6,868 KB
RANDOM_case1.txt AC 72 ms
6,872 KB
RANDOM_case2.txt AC 25 ms
6,868 KB
RANDOM_case3.txt AC 61 ms
6,868 KB
RANDOM_case4.txt AC 58 ms
6,868 KB
RANDOM_case5.txt AC 97 ms
6,868 KB
RANDOM_case6.txt AC 88 ms
6,868 KB
RANDOM_case7.txt AC 16 ms
6,868 KB
RANDOM_case8.txt AC 24 ms
8,908 KB
RANDOM_case9.txt AC 72 ms
6,872 KB
RANDOM_case10.txt AC 32 ms
8,912 KB
RANDOM_case11.txt AC 59 ms
6,872 KB
RANDOM_case12.txt AC 43 ms
6,868 KB
RANDOM_case13.txt AC 99 ms
6,872 KB
RANDOM_case14.txt AC 14 ms
6,872 KB
RANDOM_case15.txt AC 89 ms
6,868 KB
RANDOM_case16.txt AC 91 ms
6,872 KB
RANDOM_case17.txt AC 60 ms
6,872 KB
RANDOM_case18.txt AC 14 ms
6,872 KB
RANDOM_case19.txt AC 19 ms
6,872 KB
RANDOM_case20.txt AC 58 ms
6,872 KB
SMALL_case1.txt AC 3 ms
6,868 KB
SMALL_case2.txt AC 2 ms
6,868 KB
SMALL_case3.txt AC 4 ms
6,868 KB
SMALL_case4.txt AC 3 ms
6,872 KB
SMALL_case5.txt AC 2 ms
6,872 KB
SMALL_case6.txt AC 4 ms
6,868 KB
SMALL_case7.txt AC 4 ms
6,872 KB
SMALL_case8.txt AC 2 ms
6,868 KB
SMALL_case9.txt AC 2 ms
6,868 KB
SMALL_case10.txt AC 3 ms
6,868 KB
SMALL_case11.txt AC 2 ms
6,872 KB
SMALL_case12.txt AC 3 ms
6,868 KB
SMALL_case13.txt AC 3 ms
6,868 KB
SMALL_case14.txt AC 3 ms
6,872 KB
SMALL_case15.txt AC 3 ms
6,872 KB
SMALL_case16.txt AC 3 ms
6,872 KB
SMALL_case17.txt AC 2 ms
6,868 KB
SMALL_case18.txt AC 2 ms
6,868 KB
SMALL_case19.txt AC 3 ms
6,872 KB
SMALL_case20.txt AC 3 ms
6,868 KB
テストケース一括ダウンロード

ソースコード

diff #
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1000000007LL;

ll extgcd(ll a, ll b, ll &x, ll &y){
  ll d = a;
  if(b!=0){
    d = extgcd(b,a%b,y,x);
    y -= (a/b)*x;
  }else{
    x = 1; y = 0;
  }
  return d;
}

ll mod_inverse(ll a, ll m){
  ll x, y;
  extgcd(a, m, x, y);
  return (m+x%m)%m;
}

int main(){
  int N;
  cin >> N;
  vector<ll> v;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  ll ret = 0;
  vector<ll> inv(N+1, 1);
  ll q = 1;
  rep(i,N-1){
    q *= i+1;
    q %= MOD;
    inv[i+1] = mod_inverse(q, MOD);
  }
  rep(i,N){
    ll tmp = q;
    tmp *= inv[i];
    tmp %= MOD;
    tmp *= inv[N-i-1];
    tmp %= MOD;

    ret += v[i] * tmp;
    ret %= MOD;
  }
  
  cout << ret << endl;
  
  return 0;
}
0