結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー naskyanaskya
提出日時 2022-05-04 00:37:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,082 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 91,732 KB
実行使用メモリ 401,780 KB
最終ジャッジ日時 2023-09-15 22:20:37
合計ジャッジ時間 5,925 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
    A[cy][cx] = 0;

    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);
      }
    }
  }

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