結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー naskyanaskya
提出日時 2022-05-04 00:44:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 3,000 ms
コード長 1,113 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 91,572 KB
実行使用メモリ 5,704 KB
最終ジャッジ日時 2023-09-15 22:28:02
合計ジャッジ時間 3,430 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 73 ms
4,380 KB
testcase_08 AC 99 ms
4,652 KB
testcase_09 AC 128 ms
4,444 KB
testcase_10 AC 127 ms
4,376 KB
testcase_11 AC 129 ms
4,460 KB
testcase_12 AC 103 ms
4,384 KB
testcase_13 AC 63 ms
4,380 KB
testcase_14 AC 92 ms
5,652 KB
testcase_15 AC 92 ms
5,652 KB
testcase_16 AC 42 ms
4,392 KB
testcase_17 AC 97 ms
5,704 KB
testcase_18 AC 42 ms
4,432 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 84 ms
5,064 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 48 ms
4,440 KB
testcase_25 AC 91 ms
4,668 KB
権限があれば一括ダウンロードができます

ソースコード

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

  long long 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);
      A[ny][nx] = 0;
    }
  }

  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