結果

問題 No.1102 Remnants
ユーザー motmot
提出日時 2020-07-03 22:52:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,346 ms / 2,000 ms
コード長 1,415 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 83,972 KB
実行使用メモリ 8,348 KB
最終ジャッジ日時 2023-10-17 05:54:51
合計ジャッジ時間 31,946 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 908 ms
6,788 KB
testcase_01 AC 910 ms
6,788 KB
testcase_02 AC 909 ms
6,788 KB
testcase_03 AC 933 ms
6,788 KB
testcase_04 AC 930 ms
6,788 KB
testcase_05 AC 1,245 ms
8,088 KB
testcase_06 AC 956 ms
6,992 KB
testcase_07 AC 1,346 ms
8,348 KB
testcase_08 AC 929 ms
6,808 KB
testcase_09 AC 925 ms
6,852 KB
testcase_10 AC 919 ms
6,792 KB
testcase_11 AC 911 ms
6,832 KB
testcase_12 AC 917 ms
6,856 KB
testcase_13 AC 916 ms
6,852 KB
testcase_14 AC 1,091 ms
7,496 KB
testcase_15 AC 1,053 ms
7,328 KB
testcase_16 AC 1,288 ms
8,216 KB
testcase_17 AC 1,268 ms
8,132 KB
testcase_18 AC 1,280 ms
8,140 KB
testcase_19 AC 1,025 ms
7,244 KB
testcase_20 AC 934 ms
6,920 KB
testcase_21 AC 1,127 ms
7,592 KB
testcase_22 AC 1,230 ms
7,940 KB
testcase_23 AC 1,151 ms
7,672 KB
testcase_24 AC 1,080 ms
7,420 KB
testcase_25 AC 1,304 ms
8,164 KB
testcase_26 AC 929 ms
6,864 KB
testcase_27 AC 1,006 ms
7,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll fact1[200005];
ll fact2[200005];
ll N, K;

ll getcomb(ll a, ll b){
  ll ue = fact2[a-K];
  ll shita1=1, shita2=1, tmpshita1, tmpshita2;
  ll h = mod-2;
  ll two;
  while(h>0){
    tmpshita1 = fact1[b];
    tmpshita2 = fact2[a-b-K];
    two = 1;
    while(2*two<=h){
      two *= 2;
      tmpshita1 *= tmpshita1;
      tmpshita1 %= mod;
      tmpshita2 *= tmpshita2;
      tmpshita2 %= mod;
    }
    h -= two;
    shita1 *= tmpshita1;
    shita2 *= tmpshita2;
    shita1 %= mod;
    shita2 %= mod;
  }
  return ue*shita1%mod*shita2%mod;
}

int main() {
  fact1[0] = 1;
  ll tmp = 1;
  cin>>N>>K;
  for(ll i=0;i<200000000;++i){
    if(i>0) tmp *= i;
    tmp %= mod;
    if(i<200005){
      fact1[i] = tmp;
    }
    if(i>=K && i<K+200005){
      fact2[i-K] = tmp;
    }
  }
  ll A[N];
  for(int i=0;i<N;++i) cin>>A[i];
  ll ans = 0;
  for(int i=0;i<N;++i){
    ans += A[i]*getcomb(K+i, i)%mod*getcomb(K+N-i-1, N-i-1)%mod;
    ans %= mod;
  }
  cout<<ans<<endl;
}

0