結果
| 問題 | 
                            No.1949 足し算するだけのパズルゲーム(2)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tnakao0123
                         | 
                    
| 提出日時 | 2022-05-21 14:12:13 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 65 ms / 3,000 ms | 
| コード長 | 1,272 bytes | 
| コンパイル時間 | 474 ms | 
| コンパイル使用メモリ | 59,084 KB | 
| 実行使用メモリ | 5,908 KB | 
| 最終ジャッジ日時 | 2024-09-20 11:45:29 | 
| 合計ジャッジ時間 | 2,363 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 26 | 
ソースコード
/* -*- 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;
}
            
            
            
        
            
tnakao0123