結果

問題 No.770 Median Sequence
ユーザー kriiikriii
提出日時 2018-12-18 02:12:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 374 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 33,852 KB
実行使用メモリ 143,964 KB
最終ジャッジ日時 2023-10-25 23:34:19
合計ジャッジ時間 3,426 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,260 KB
testcase_01 AC 2 ms
5,240 KB
testcase_02 AC 3 ms
6,108 KB
testcase_03 AC 2 ms
5,244 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 3 ms
5,296 KB
testcase_06 AC 3 ms
5,568 KB
testcase_07 AC 2 ms
5,512 KB
testcase_08 AC 17 ms
13,772 KB
testcase_09 AC 48 ms
27,552 KB
testcase_10 AC 19 ms
14,292 KB
testcase_11 AC 9 ms
8,952 KB
testcase_12 AC 351 ms
137,732 KB
testcase_13 AC 178 ms
80,124 KB
testcase_14 AC 96 ms
47,968 KB
testcase_15 AC 276 ms
120,088 KB
testcase_16 AC 49 ms
28,304 KB
testcase_17 AC 372 ms
143,964 KB
testcase_18 AC 374 ms
143,920 KB
testcase_19 AC 369 ms
143,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const long long mod = 1000000007;

int N;
long long A[3003][3003],B[3003][3003];

void add(long long &a, long long b)
{
	a = (a + b) % mod;
}

int main()
{
	scanf ("%d",&N);

	for (int i=1;i<=N;i++) A[N][i] = 1;
	for (int i=N;i>=2;i--){
		for (int j=1;j<=N;j++){
			if (N - j <= i - 1){
				add(A[i-(N-j)-1][1],B[i][j]);
				add(A[i-(N-j)-1][j],mod-B[i][j]);
			}
			add(B[i-1][j],B[i][j]);
			if (N - j <= i - 1 && j + 1 <= N){
				add(B[i-1][j+1],B[i][j]);
				add(B[i-1][j+1],A[i][j]);
			}
			add(A[i-1][1],A[i][j]);
			add(A[i-1][j+1],mod-A[i][j]);
		}
		for (int j=1;j<=N;j++) add(A[i-1][j],A[i-1][j-1]);
		add(A[i-1][N],B[i-1][N]);
		B[i-1][N] = 0;
	}

	long long ans = 0;
	for (int i=1;i<=N;i++) add(ans,A[1][i]+B[1][i]);
	printf ("%lld\n",ans);

	return 0;
}
0