結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー SSRSSSRS
提出日時 2022-05-20 21:43:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 178 ms / 3,000 ms
コード長 1,341 bytes
コンパイル時間 2,191 ms
コンパイル使用メモリ 184,416 KB
実行使用メモリ 8,504 KB
最終ジャッジ日時 2023-10-20 12:10:52
合計ジャッジ時間 5,106 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 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 112 ms
4,732 KB
testcase_08 AC 110 ms
4,712 KB
testcase_09 AC 153 ms
4,720 KB
testcase_10 AC 161 ms
4,732 KB
testcase_11 AC 167 ms
4,780 KB
testcase_12 AC 134 ms
4,788 KB
testcase_13 AC 94 ms
4,756 KB
testcase_14 AC 149 ms
8,504 KB
testcase_15 AC 149 ms
8,504 KB
testcase_16 AC 47 ms
4,712 KB
testcase_17 AC 178 ms
8,504 KB
testcase_18 AC 46 ms
4,712 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 139 ms
8,460 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 67 ms
4,756 KB
testcase_25 AC 117 ms
4,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
int main(){
  int H, W, Y, X;
  cin >> H >> W >> Y >> X;
  Y--;
  X--;
  vector<vector<int>> A(H, vector<int>(W));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> A[i][j];
    }
  }
  long long C = A[Y][X];
  vector<vector<bool>> used(H, vector<bool>(W, false));
  used[Y][X] = true;
  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq;
  for (int i = 0; i < 4; i++){
    int x = Y + dx[i];
    int y = X + dy[i];
    if (0 <= x && x < H && 0 <= y && y < W){
      pq.push(make_tuple(A[x][y], x, y));
    }
  }
  bool ok = true;
  while (!pq.empty()){
    long long P = get<0>(pq.top());
    int x = get<1>(pq.top());
    int y = get<2>(pq.top());
    pq.pop();
    if (!used[x][y]){
      used[x][y] = true;
      if (P >= C){
        ok = false;
      } else {
        C += P;
        for (int i = 0; i < 4; i++){
          int x2 = x + dx[i];
          int y2 = y + dy[i];
          if (0 <= x2 && x2 < H && 0 <= y2 && y2 < W){
            if (!used[x2][y2]){
              pq.push(make_tuple(A[x2][y2], x2, y2));
            }
          }
        }
      }
    }
  }
  if (ok){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
0