結果

問題 No.770 Median Sequence
ユーザー PulmnPulmn
提出日時 2018-11-21 21:13:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 352 ms / 2,000 ms
コード長 654 bytes
コンパイル時間 501 ms
コンパイル使用メモリ 65,540 KB
実行使用メモリ 44,144 KB
最終ジャッジ日時 2023-08-26 02:41:21
合計ジャッジ時間 3,256 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,416 KB
testcase_01 AC 3 ms
5,424 KB
testcase_02 AC 3 ms
5,436 KB
testcase_03 AC 3 ms
5,516 KB
testcase_04 AC 3 ms
5,576 KB
testcase_05 AC 3 ms
5,388 KB
testcase_06 AC 3 ms
5,664 KB
testcase_07 AC 3 ms
5,396 KB
testcase_08 AC 7 ms
6,724 KB
testcase_09 AC 19 ms
9,644 KB
testcase_10 AC 8 ms
7,104 KB
testcase_11 AC 4 ms
5,916 KB
testcase_12 AC 311 ms
40,524 KB
testcase_13 AC 120 ms
22,188 KB
testcase_14 AC 54 ms
14,476 KB
testcase_15 AC 220 ms
31,928 KB
testcase_16 AC 22 ms
9,884 KB
testcase_17 AC 352 ms
44,080 KB
testcase_18 AC 343 ms
44,144 KB
testcase_19 AC 343 ms
43,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;

const ll mod=1e9+7,M=3005;
ll N,a[M],b[M],s[M],res=0;
queue<ll> q[M];

int main(){
	cin>>N;
	for(int i=0;i<N-1;i++) for(int j=0;j<N-i-1;j++) q[i].push(j==N-i-2);
	a[N-1]++;
	fill(s,s+N,1);
	for(int i=1;i<N;i++){
		fill(b,b+N,0);
		ll S=0;
		for(int j=0;;j++){
			b[j]=((j==N-1?S:q[j].front())+a[j]+a[j+1])%mod;
			if(j==N-1) break;
			ll t=q[j].front(),tmp=s[j];q[j].pop();
			q[j].push(S);
			(s[j]+=S-t+mod)%=mod;
			(S+=tmp)%=mod;
		}
		for(int j=0;j<N;j++){
			(s[j]+=b[j]-a[j]+mod)%=mod;
			a[j]=b[j];
		}
	}
	for(int i=0;i<N;i++) (res+=s[i])%=mod;
	cout<<res<<endl;
}
0