結果

問題 No.1102 Remnants
ユーザー kotatsugamekotatsugame
提出日時 2020-07-03 21:49:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 693 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 66,588 KB
実行使用メモリ 8,808 KB
最終ジャッジ日時 2023-10-17 00:37:23
合計ジャッジ時間 3,493 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,688 KB
testcase_01 AC 2 ms
5,688 KB
testcase_02 AC 2 ms
5,688 KB
testcase_03 AC 2 ms
5,688 KB
testcase_04 AC 2 ms
5,688 KB
testcase_05 AC 38 ms
6,988 KB
testcase_06 AC 20 ms
6,096 KB
testcase_07 AC 137 ms
8,808 KB
testcase_08 AC 3 ms
5,708 KB
testcase_09 AC 7 ms
5,816 KB
testcase_10 AC 3 ms
5,704 KB
testcase_11 AC 5 ms
5,776 KB
testcase_12 AC 7 ms
5,832 KB
testcase_13 AC 5 ms
5,756 KB
testcase_14 AC 28 ms
6,400 KB
testcase_15 AC 41 ms
6,776 KB
testcase_16 AC 104 ms
8,552 KB
testcase_17 AC 98 ms
8,376 KB
testcase_18 AC 120 ms
8,392 KB
testcase_19 AC 42 ms
6,600 KB
testcase_20 AC 14 ms
5,960 KB
testcase_21 AC 72 ms
7,304 KB
testcase_22 AC 103 ms
7,992 KB
testcase_23 AC 80 ms
7,464 KB
testcase_24 AC 57 ms
6,952 KB
testcase_25 AC 125 ms
8,440 KB
testcase_26 AC 9 ms
5,840 KB
testcase_27 AC 34 ms
6,400 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
const long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
int N,K;
long A[2<<17];
long S[2<<17];
//H(a,K)=C(a+K-1,K)=C(a+K-1,a-1)
long H[2<<17];
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		S[i+1]=S[i]+A[i];
		S[i+1]%=mod;
	}
	if(K==0)
	{
		cout<<S[N]<<endl;
		return 0;
	}
	K--;
	H[1]=1;
	for(int i=2;i<=N;i++)
	{
		H[i]=H[i-1]*(K+i-1)%mod*power(i-1,mod-2)%mod;
	}
	long ans=0,cum=0;
	for(int i=1;i<=N;i++)
	{
		(cum+=H[i])%=mod;
		(ans+=S[i]*cum%mod*H[N-i+1]%mod)%=mod;
	}
	cum=0;
	for(int i=N;i>=1;i--)
	{
		(cum+=H[N-i+1])%=mod;
		(ans+=(mod-S[i-1])*cum%mod*H[i]%mod)%=mod;
	}
	cout<<ans<<endl;
}
0