結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー pengin_2000pengin_2000
提出日時 2022-07-21 13:44:59
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,161 bytes
コンパイル時間 2,839 ms
コンパイル使用メモリ 29,732 KB
実行使用メモリ 7,736 KB
最終ジャッジ日時 2023-09-15 15:21:15
合計ジャッジ時間 2,674 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,504 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 0 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 27 ms
7,552 KB
testcase_08 AC 39 ms
7,600 KB
testcase_09 AC 39 ms
7,628 KB
testcase_10 AC 39 ms
7,692 KB
testcase_11 AC 38 ms
7,720 KB
testcase_12 AC 33 ms
7,688 KB
testcase_13 AC 33 ms
7,552 KB
testcase_14 AC 33 ms
7,716 KB
testcase_15 AC 32 ms
7,688 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 3 ms
7,724 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 33 ms
7,736 KB
testcase_21 AC 32 ms
7,632 KB
testcase_22 AC 29 ms
7,736 KB
testcase_23 AC 29 ms
7,728 KB
testcase_24 AC 29 ms
7,676 KB
testcase_25 AC 36 ms
7,620 KB
testcase_26 AC 38 ms
7,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int max(long long int a, long long int b)
{
	if (a > b)
		return a;
	else
		return b;
}
long long int a[502][502];
long long int dp[2][502][502];
int main()
{
	int h, w;
	scanf("%d %d", &h, &w);
	int i, j;
	for (i = 0; i < h; i++)
		for (j = 0; j < w; j++)
			scanf("%lld", &a[i][j]);
	for (i = 0; i <= h; i++)
		for (j = 0; j <= w; j++)
			dp[0][i][j] = dp[1][i][j] = 0;
	dp[0][0][0] = a[0][0];
	for (i = 0; i < h; i++)
	{
		for (j = 0; j < w; j++)
		{
			if (i == h - 1 && j == w - 1)
				break;
			if (i != 0 || j != 0)
			{
				if (dp[1][i][j] > a[i][j])
					dp[1][i][j] += a[i][j];
				else
					dp[1][i][j] = 0;
				if (dp[0][i][j] > a[i][j])
					dp[0][i][j] += a[i][j];
				else
				{
					dp[1][i][j] = max(dp[1][i][j], dp[0][i][j]);
					dp[0][i][j] = 0;
				}
			}
			dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[0][i][j]);
			dp[0][i][j + 1] = max(dp[0][i][j + 1], dp[0][i][j]);
			dp[1][i + 1][j] = max(dp[1][i + 1][j], dp[1][i][j]);
			dp[1][i][j + 1] = max(dp[1][i][j + 1], dp[1][i][j]);
		}
	}
	if (max(dp[0][h - 1][w - 1], dp[1][h - 1][w - 1]) > a[h - 1][w - 1])
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}
0