結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー furafura
提出日時 2023-09-10 13:35:04
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 156 ms / 3,000 ms
コード長 2,729 bytes
コンパイル時間 3,882 ms
コンパイル使用メモリ 272,980 KB
実行使用メモリ 10,476 KB
最終ジャッジ日時 2023-09-10 13:35:12
合計ジャッジ時間 6,682 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 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,380 KB
testcase_07 AC 68 ms
5,152 KB
testcase_08 AC 34 ms
5,220 KB
testcase_09 AC 82 ms
5,104 KB
testcase_10 AC 74 ms
5,136 KB
testcase_11 AC 86 ms
5,400 KB
testcase_12 AC 80 ms
5,268 KB
testcase_13 AC 70 ms
5,216 KB
testcase_14 AC 98 ms
9,548 KB
testcase_15 AC 98 ms
9,860 KB
testcase_16 AC 20 ms
5,148 KB
testcase_17 AC 156 ms
10,476 KB
testcase_18 AC 19 ms
5,152 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 115 ms
9,792 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 42 ms
5,156 KB
testcase_25 AC 70 ms
5,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef TEMPLATE_HPP
#define TEMPLATE_HPP

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define impl_overload4(a, b, c, d, e, ...) e
#define impl_overload5(a, b, c, d, e, f, ...) f
#define impl_overload6(a, b, c, d, e, f, g, ...) g
#define impl_overload7(a, b, c, d, e, f, g, h, ...) h

// clang-format off
#define impl_rep4(i, a, b, c) for (int i = (a); i < (b); i += (c))
#define impl_rep3(i, a, b) impl_rep4(i, a, b, 1)
#define impl_rep2(i, n) impl_rep3(i, 0, n)
#define impl_rep1(n) for (int _ = 0; _ < (n); ++_)
#define rep(...) impl_overload4(__VA_ARGS__, impl_rep4, impl_rep3, impl_rep2, impl_rep1)(__VA_ARGS__)

#define impl_rrep4(i, a, b, c) for (int i = (b) - 1; i >= (a); i -= (c))
#define impl_rrep3(i, a, b) impl_rrep4(i, a, b, 1)
#define impl_rrep2(i, n) impl_rrep3(i, 0, n)
#define rrep(...) impl_overload4(__VA_ARGS__, impl_rrep4, impl_rrep3, impl_rrep2)(__VA_ARGS__)
// clang-format on

#define all(v) std::begin(v), std::end(v)

template<typename T>
constexpr int bit(T x, unsigned int k) {
    return (x >> k) & 1;
}

template<typename T>
constexpr bool chmax(T& a, const T& b) {
    return a < b ? a = b, true : false;
}
template<typename T>
constexpr bool chmin(T& a, const T& b) {
    return a > b ? a = b, true : false;
}

void yesno(bool b) {
    std::cout << (b ? "Yes" : "No") << "\n";
}
void yes() {
    yesno(true);
}
void no() {
    yesno(false);
}

struct Setup {
    Setup() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        std::cout << std::fixed << std::setprecision(11);
    }
} setup;

#ifdef LOCAL
#include "template_local.hpp"
#else
#define show(...) ((void)0)
#endif

using uint = unsigned int;
using lint = long long;
using ulint = unsigned long long;

using namespace std;

#endif // TEMPLATE_HPP

constexpr int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};

int main() {
    int h, w, x0, y0;
    cin >> h >> w >> x0 >> y0;
    x0--;
    y0--;
    vector A(h, vector<lint>(w));
    rep (i, h) {
        rep (j, w) cin >> A[i][j];
    }

    lint p = A[x0][y0];
    A[x0][y0] = 0;

    priority_queue<tuple<lint, int, int>> Q;
    Q.emplace(0, x0, y0);
    while (not Q.empty()) {
        auto [_, x, y] = Q.top();
        Q.pop();

        if (A[x][y] == -1 or p <= A[x][y]) continue;
        p += A[x][y];
        A[x][y] = -1;

        rep (k, 4) {
            int x2 = x + dx[k], y2 = y + dy[k];
            if (0 <= x2 and x2 < h and 0 <= y2 and y2 < w and A[x2][y2] != -1) {
                Q.emplace(-A[x2][y2], x2, y2);
            }
        }
    }

    bool ok = true;
    rep (i, h) {
        rep (j, w) {
            if (A[i][j] != -1) ok = false;
        }
    }
    yesno(ok);

    return 0;
}
0