結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー naskyanaskya
提出日時 2022-05-04 00:40:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,086 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 91,812 KB
実行使用メモリ 6,028 KB
最終ジャッジ日時 2023-09-15 22:24:22
合計ジャッジ時間 3,362 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 73 ms
4,380 KB
testcase_08 AC 101 ms
4,488 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 91 ms
5,776 KB
testcase_15 AC 91 ms
6,028 KB
testcase_16 AC 42 ms
4,420 KB
testcase_17 AC 95 ms
5,660 KB
testcase_18 AC 42 ms
4,408 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 WA -
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 48 ms
4,432 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iterator>
#include <queue>
#include <tuple>
#include <vector>

int main() {
  int H, W, Y, X;
  std::cin >> H >> W >> Y >> X;

  --Y;
  --X;

  std::vector A(H, std::vector<int>(W));
  for (int i = 0; i < H; ++i) {
    std::copy_n(std::istream_iterator<int>(std::cin), W, A[i].begin());
  }

  int S = A[Y][X];

  A[Y][X] = 0;

  std::priority_queue<std::tuple<int, int, int>> q;
  constexpr int dy[] {0, 1, 0, -1}, dx[] {1, 0, -1, 0};

  for (int i = 0; i < 4; ++i) {
    const int ny = Y + dy[i], nx = X + dx[i];
    if (0 <= ny && ny < H && 0 <= nx && nx < W) {
      q.emplace(-A[ny][nx], ny, nx);
    }
  }

  while (!q.empty()) {
    const auto [cs, cy, cx] = q.top();
    q.pop();

    if (S <= -cs) {
      std::cout << "No\n";
      return 0;
    }

    S += -cs;

    for (int i = 0; i < 4; ++i) {
      const int ny = cy + dy[i], nx = cx + dx[i];
      if (0 <= ny && ny < H && 0 <= nx && nx < W && A[ny][nx] != 0) {
        q.emplace(-A[ny][nx], ny, nx);
        A[ny][nx] = 0;
      }
    }
  }

  std::cout << "Yes\n";
}
0