結果
| 問題 | No.1102 Remnants | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-07-19 15:48:18 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 306 ms / 2,000 ms | 
| コード長 | 795 bytes | 
| コンパイル時間 | 876 ms | 
| コンパイル使用メモリ | 68,848 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-16 05:55:19 | 
| 合計ジャッジ時間 | 5,806 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;
    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}
int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> sum(n, 0);
    ll comb = 1, a = k, b = 1;
    sum[0] = 1;
    for(int i = 1; i < n; i++){
        comb *= a++;
        comb %= mod;
        comb *= modpow(b++, mod-2, mod);
        comb %= mod;
        sum[i] = (comb+sum[i-1])%mod;
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll x;
        cin >> x;
        ans += x*sum[i]%mod*sum[n-1-i]%mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}
            
            
            
        