結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー tnakao0123tnakao0123
提出日時 2022-05-21 14:12:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 3,000 ms
コード長 1,272 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 57,260 KB
実行使用メモリ 5,660 KB
最終ジャッジ日時 2023-10-20 16:12:14
合計ジャッジ時間 2,735 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 42 ms
4,348 KB
testcase_08 AC 34 ms
4,348 KB
testcase_09 AC 53 ms
5,660 KB
testcase_10 AC 49 ms
5,660 KB
testcase_11 AC 51 ms
4,936 KB
testcase_12 AC 44 ms
4,940 KB
testcase_13 AC 39 ms
5,660 KB
testcase_14 AC 41 ms
5,660 KB
testcase_15 AC 41 ms
5,660 KB
testcase_16 AC 24 ms
4,348 KB
testcase_17 AC 61 ms
5,612 KB
testcase_18 AC 23 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 50 ms
5,616 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 31 ms
4,764 KB
testcase_25 AC 48 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

/* constant */

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

const int dxs[] = { 1, 0, -1, 0 }, dys[] = { 0, -1, 0, 1 };

/* typedef */

typedef long long ll;

struct Elm {
  int a, y, x;
  Elm() {}
  Elm(int _a, int _y, int _x): a(_a), y(_y), x(_x) {}

  bool operator<(const Elm &e) const { return a > e.a; }
};

/* global variables */

int as[MAX_H][MAX_W];
bool used[MAX_H][MAX_W];

/* subroutines */

/* main */

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

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

  used[sy][sx] = true;
  priority_queue<Elm> q;
  q.push(Elm(as[sy][sx], sy, sx));

  ll sum = 0;

  while (! q.empty()) {
    Elm e = q.top(); q.pop();

    if (sum > 0 && sum <= e.a) { puts("No"); return 0; }

    sum += e.a;
    for (int di = 0; di < 4; di++) {
      int vy = e.y + dys[di], vx = e.x + dxs[di];
      if (vy >= 0 && vy < h && vx >= 0 && vx < w && ! used[vy][vx]) {
	used[vy][vx] = true;
	q.push(Elm(as[vy][vx], vy, vx));
      }
    }
  }

  puts("Yes");
  return 0;
}
0