結果

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

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
LEARGE_case1.txt AC 104 ms
3,160 KB
LEARGE_case2.txt AC 102 ms
3,168 KB
LEARGE_case3.txt AC 103 ms
3,168 KB
LEARGE_case4.txt AC 103 ms
3,168 KB
LEARGE_case5.txt AC 103 ms
3,164 KB
LEARGE_case6.txt AC 102 ms
3,164 KB
LEARGE_case7.txt AC 118 ms
3,168 KB
LEARGE_case8.txt AC 124 ms
3,164 KB
LEARGE_case9.txt AC 102 ms
3,164 KB
LEARGE_case10.txt AC 103 ms
3,164 KB
LEARGE_case11.txt AC 103 ms
3,164 KB
LEARGE_case12.txt AC 101 ms
3,168 KB
LEARGE_case13.txt AC 105 ms
3,164 KB
LEARGE_case14.txt AC 102 ms
3,164 KB
LEARGE_case15.txt AC 105 ms
3,164 KB
LEARGE_case16.txt AC 102 ms
3,168 KB
LEARGE_case17.txt AC 104 ms
3,164 KB
LEARGE_case18.txt AC 105 ms
3,168 KB
LEARGE_case19.txt AC 112 ms
3,168 KB
LEARGE_case20.txt AC 123 ms
3,164 KB
RANDOM_case1.txt AC 75 ms
2,636 KB
RANDOM_case2.txt AC 26 ms
1,820 KB
RANDOM_case3.txt AC 64 ms
2,384 KB
RANDOM_case4.txt AC 60 ms
2,380 KB
RANDOM_case5.txt AC 101 ms
2,900 KB
RANDOM_case6.txt AC 90 ms
2,900 KB
RANDOM_case7.txt AC 17 ms
1,656 KB
RANDOM_case8.txt AC 24 ms
1,816 KB
RANDOM_case9.txt AC 75 ms
2,636 KB
RANDOM_case10.txt AC 34 ms
1,988 KB
RANDOM_case11.txt AC 63 ms
2,384 KB
RANDOM_case12.txt AC 46 ms
2,120 KB
RANDOM_case13.txt AC 105 ms
3,164 KB
RANDOM_case14.txt AC 14 ms
1,656 KB
RANDOM_case15.txt AC 93 ms
2,904 KB
RANDOM_case16.txt AC 111 ms
2,900 KB
RANDOM_case17.txt AC 71 ms
2,380 KB
RANDOM_case18.txt AC 15 ms
1,656 KB
RANDOM_case19.txt AC 29 ms
1,652 KB
RANDOM_case20.txt AC 63 ms
2,380 KB
SMALL_case1.txt AC 4 ms
1,528 KB
SMALL_case2.txt AC 4 ms
1,528 KB
SMALL_case3.txt AC 4 ms
1,532 KB
SMALL_case4.txt AC 4 ms
1,528 KB
SMALL_case5.txt AC 4 ms
1,528 KB
SMALL_case6.txt AC 5 ms
1,528 KB
SMALL_case7.txt AC 3 ms
1,532 KB
SMALL_case8.txt AC 4 ms
1,532 KB
SMALL_case9.txt AC 4 ms
1,528 KB
SMALL_case10.txt AC 4 ms
1,528 KB
SMALL_case11.txt AC 4 ms
1,532 KB
SMALL_case12.txt AC 4 ms
1,520 KB
SMALL_case13.txt AC 4 ms
1,532 KB
SMALL_case14.txt AC 4 ms
1,528 KB
SMALL_case15.txt AC 5 ms
1,528 KB
SMALL_case16.txt AC 3 ms
1,524 KB
SMALL_case17.txt AC 4 ms
1,532 KB
SMALL_case18.txt AC 3 ms
1,532 KB
SMALL_case19.txt AC 4 ms
1,528 KB
SMALL_case20.txt AC 4 ms
1,532 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