結果

問題 No.797 Noelちゃんとピラミッド
ユーザー peroonperoon
提出日時 2019-03-15 21:46:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,717 bytes
コンパイル時間 1,930 ms
コンパイル使用メモリ 97,560 KB
実行使用メモリ 5,516 KB
最終ジャッジ日時 2023-09-14 13:19:19
合計ジャッジ時間 5,756 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
5,180 KB
testcase_01 AC 33 ms
4,924 KB
testcase_02 AC 33 ms
4,888 KB
testcase_03 AC 46 ms
5,444 KB
testcase_04 AC 46 ms
5,452 KB
testcase_05 AC 45 ms
5,432 KB
testcase_06 AC 47 ms
5,424 KB
testcase_07 AC 45 ms
5,396 KB
testcase_08 AC 46 ms
5,468 KB
testcase_09 AC 46 ms
5,432 KB
testcase_10 AC 45 ms
5,432 KB
testcase_11 AC 45 ms
5,376 KB
testcase_12 AC 45 ms
5,316 KB
testcase_13 AC 45 ms
5,320 KB
testcase_14 AC 45 ms
5,400 KB
testcase_15 AC 45 ms
5,452 KB
testcase_16 AC 44 ms
5,512 KB
testcase_17 AC 46 ms
5,448 KB
testcase_18 AC 45 ms
5,316 KB
testcase_19 AC 44 ms
5,392 KB
testcase_20 AC 44 ms
5,516 KB
testcase_21 AC 45 ms
5,296 KB
testcase_22 AC 45 ms
5,416 KB
testcase_23 AC 42 ms
5,192 KB
testcase_24 AC 36 ms
4,872 KB
testcase_25 AC 40 ms
5,052 KB
testcase_26 AC 40 ms
5,096 KB
testcase_27 AC 45 ms
5,516 KB
testcase_28 AC 44 ms
5,352 KB
testcase_29 AC 34 ms
5,264 KB
testcase_30 AC 35 ms
4,888 KB
testcase_31 AC 41 ms
5,368 KB
testcase_32 AC 36 ms
4,968 KB
testcase_33 AC 40 ms
5,108 KB
testcase_34 AC 37 ms
4,892 KB
testcase_35 AC 45 ms
5,512 KB
testcase_36 AC 34 ms
4,992 KB
testcase_37 AC 43 ms
5,416 KB
testcase_38 AC 44 ms
5,452 KB
testcase_39 AC 40 ms
5,088 KB
testcase_40 AC 34 ms
4,988 KB
testcase_41 AC 35 ms
5,024 KB
testcase_42 AC 40 ms
5,048 KB
testcase_43 AC 32 ms
4,972 KB
testcase_44 AC 32 ms
4,932 KB
testcase_45 AC 32 ms
4,920 KB
testcase_46 AC 32 ms
4,876 KB
testcase_47 AC 33 ms
5,076 KB
testcase_48 AC 33 ms
5,028 KB
testcase_49 AC 33 ms
4,912 KB
testcase_50 AC 33 ms
4,872 KB
testcase_51 AC 33 ms
4,872 KB
testcase_52 AC 32 ms
4,896 KB
testcase_53 AC 34 ms
4,968 KB
testcase_54 AC 33 ms
4,924 KB
testcase_55 AC 33 ms
4,892 KB
testcase_56 AC 33 ms
4,968 KB
testcase_57 AC 33 ms
4,968 KB
testcase_58 AC 33 ms
4,944 KB
testcase_59 AC 33 ms
4,924 KB
testcase_60 AC 33 ms
4,872 KB
testcase_61 AC 32 ms
4,892 KB
testcase_62 AC 33 ms
5,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const int N_MAX = 100010;
ll Per[N_MAX] = {}; // n!
ll Per_inv[N_MAX] = {}; //(n!)^-1

ll nCr(ll n, ll r){
    if(n<r) return 0;
 
    if (n == r || r == 0)
        return 1;
    else
        return Per[n] * Per_inv[n-r] % mod * Per_inv[r] % mod;  
}
 
// a^b mod p
ll mod_pow(ll a, ll b){
    if(b==0) return 1;
 
    // 肩が奇数
    if(b%2==1){
        return a * mod_pow(a, b-1) % mod;
    }
    else{
        return mod_pow(a*a % mod, b/2) % mod;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // nCr高速化準備
    Per[1] = 1;
    FOR(i, 2, N_MAX){
        Per[i] = i * Per[i-1] % mod;
    }
    Per_inv[1] = 1;
    FOR(i, 2, N_MAX){
        Per_inv[i] = mod_pow(Per[i], 1000000005);
    }

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    ll sum = 0;
    FOR(i, 0, N){
        sum += A[i] * nCr(N-1, i);
        sum %= mod;
    }

    p(sum);
    
    return 0;
}
0