結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー tnakao0123tnakao0123
提出日時 2022-05-21 02:01:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,179 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 42,332 KB
実行使用メモリ 7,960 KB
最終ジャッジ日時 2023-10-20 15:27:38
合計ジャッジ時間 2,254 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,136 KB
testcase_01 AC 2 ms
5,132 KB
testcase_02 AC 3 ms
5,132 KB
testcase_03 AC 2 ms
5,144 KB
testcase_04 AC 2 ms
5,132 KB
testcase_05 AC 2 ms
5,132 KB
testcase_06 AC 2 ms
5,132 KB
testcase_07 AC 32 ms
7,956 KB
testcase_08 AC 35 ms
5,248 KB
testcase_09 AC 39 ms
7,956 KB
testcase_10 AC 39 ms
7,960 KB
testcase_11 AC 35 ms
6,644 KB
testcase_12 AC 31 ms
6,844 KB
testcase_13 AC 32 ms
6,876 KB
testcase_14 AC 32 ms
6,964 KB
testcase_15 AC 31 ms
6,676 KB
testcase_16 AC 2 ms
5,140 KB
testcase_17 AC 4 ms
6,636 KB
testcase_18 AC 2 ms
5,176 KB
testcase_19 AC 2 ms
5,156 KB
testcase_20 AC 37 ms
7,960 KB
testcase_21 AC 36 ms
7,952 KB
testcase_22 AC 26 ms
6,640 KB
testcase_23 AC 28 ms
6,636 KB
testcase_24 AC 33 ms
7,960 KB
testcase_25 AC 38 ms
7,936 KB
testcase_26 AC 42 ms
7,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1948.cc:  No.1948 足し算するだけのパズルゲーム(1) - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_H = 500;
const int MAX_W = 500;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_H][MAX_W];
ll dp[MAX_H][MAX_W][2];

/* subroutines */

inline void setmax(ll &a, ll b) { if (a < b) a = b; }

void check(int i, int j, int k, int i1, int j1, int h, int w) {
  if (dp[i][j][k] > as[i1][j1])
    setmax(dp[i1][j1][k], dp[i][j][k] + as[i1][j1]);
  else if (k == 0 && ! (i1 == h - 1 && j1 == w - 1))
    setmax(dp[i1][j1][1], dp[i][j][0]);
}

/* main */

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

  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) scanf("%d", as[i] + j);

  dp[0][0][0] = as[0][0];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      for (int k = 0; k < 2; k++)
	if (dp[i][j][k] > 0) {
	  if (i + 1 < h) check(i, j, k, i + 1, j, h, w);
	  if (j + 1 < w) check(i, j, k, i, j + 1, h, w);
	}
  
  if (dp[h - 1][w - 1][0] > 0 || dp[h - 1][w - 1][1] > 0)
    puts("Yes");
  else
    puts("No");

  return 0;
}
0