結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー atjh16atjh16
提出日時 2022-09-23 13:49:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,145 bytes
コンパイル時間 1,905 ms
コンパイル使用メモリ 200,140 KB
実行使用メモリ 9,396 KB
最終ジャッジ日時 2023-08-23 20:49:55
合計ジャッジ時間 5,792 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,384 KB
testcase_01 AC 2 ms
5,492 KB
testcase_02 AC 3 ms
5,508 KB
testcase_03 AC 2 ms
5,592 KB
testcase_04 AC 2 ms
5,404 KB
testcase_05 AC 2 ms
5,388 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 55 ms
9,128 KB
testcase_08 AC 108 ms
9,292 KB
testcase_09 AC 108 ms
9,216 KB
testcase_10 AC 108 ms
9,124 KB
testcase_11 AC 108 ms
9,172 KB
testcase_12 AC 79 ms
9,172 KB
testcase_13 AC 79 ms
9,396 KB
testcase_14 AC 80 ms
9,172 KB
testcase_15 AC 81 ms
9,296 KB
testcase_16 AC 3 ms
5,352 KB
testcase_17 AC 5 ms
8,168 KB
testcase_18 AC 2 ms
5,476 KB
testcase_19 AC 2 ms
5,360 KB
testcase_20 AC 78 ms
9,292 KB
testcase_21 AC 78 ms
9,180 KB
testcase_22 AC 65 ms
9,188 KB
testcase_23 AC 66 ms
9,176 KB
testcase_24 AC 65 ms
9,160 KB
testcase_25 AC 97 ms
9,172 KB
testcase_26 AC 101 ms
9,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int h, w;
long long a[500][500], b[500][500][2];

int main() {
	cin >> h >> w;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}

	b[0][0][0] = a[0][0];

	for (int i = 1; i < h + w - 1; i++) {
		for (int j = max(0, i - h); j <= min(i, w - 1); j++) {
			if (i - j > 0) {
				if (b[i - j - 1][j][0] > a[i - j][j]) {
					b[i - j][j][0] = b[i - j - 1][j][0] + a[i - j][j];
				}
				else {
					b[i - j][j][1] = b[i - j - 1][j][0];
				}

				if (b[i - j - 1][j][1] > a[i - j][j]) {
					b[i - j][j][1] = max(b[i - j][j][1], b[i - j - 1][j][1] + a[i - j][j]);
				}
			}

			if (j > 0) {
				if (b[i - j][j - 1][0] > a[i - j][j]) {
					b[i - j][j][0] = max(b[i - j][j][0], b[i - j][j - 1][0] + a[i - j][j]);
				}
				else {
					b[i - j][j][1] = max(b[i - j][j][1], b[i - j][j - 1][0]);
				}

				if (b[i - j][j - 1][1] > a[i - j][j]) {
					b[i - j][j][1] = max(b[i - j][j][1], b[i - j][j - 1][1] + a[i - j][j]);
				}
			}
		}
	}

	if (max(b[h - 1][w - 1][0], b[h - 1][w - 1][1]) > a[h - 1][w - 1])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
0