結果

問題 No.2826 Earthwork
ユーザー 🦠みどりむし🦠みどりむし
提出日時 2024-06-26 10:49:37
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,904 bytes
コンパイル時間 1,695 ms
コンパイル使用メモリ 129,096 KB
実行使用メモリ 30,100 KB
最終ジャッジ日時 2024-06-26 11:37:20
合計ジャッジ時間 26,005 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 38 ms
5,376 KB
testcase_02 AC 1,006 ms
29,456 KB
testcase_03 AC 117 ms
5,776 KB
testcase_04 AC 883 ms
25,432 KB
testcase_05 WA -
testcase_06 AC 550 ms
17,536 KB
testcase_07 AC 695 ms
21,140 KB
testcase_08 AC 1,014 ms
29,588 KB
testcase_09 AC 1,038 ms
29,820 KB
testcase_10 AC 1,102 ms
29,452 KB
testcase_11 WA -
testcase_12 AC 39 ms
5,376 KB
testcase_13 AC 340 ms
11,476 KB
testcase_14 AC 1,146 ms
30,100 KB
testcase_15 AC 264 ms
10,104 KB
testcase_16 AC 466 ms
17,408 KB
testcase_17 AC 172 ms
7,424 KB
testcase_18 AC 423 ms
17,036 KB
testcase_19 AC 191 ms
8,960 KB
testcase_20 AC 863 ms
24,848 KB
testcase_21 WA -
testcase_22 AC 730 ms
20,808 KB
testcase_23 AC 683 ms
20,284 KB
testcase_24 AC 1,073 ms
29,588 KB
testcase_25 AC 388 ms
20,916 KB
testcase_26 AC 638 ms
20,752 KB
testcase_27 AC 29 ms
5,376 KB
testcase_28 AC 1,116 ms
30,028 KB
testcase_29 AC 88 ms
5,504 KB
testcase_30 AC 57 ms
5,376 KB
testcase_31 AC 90 ms
5,376 KB
testcase_32 AC 35 ms
5,376 KB
testcase_33 AC 610 ms
18,040 KB
testcase_34 AC 1,063 ms
29,440 KB
testcase_35 AC 249 ms
9,636 KB
testcase_36 AC 1,066 ms
29,852 KB
testcase_37 AC 1,101 ms
29,656 KB
testcase_38 AC 544 ms
16,900 KB
testcase_39 WA -
testcase_40 AC 48 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdint>
#include <iostream>
#include <utility>
#include <functional>
#include <vector>
#include <queue>
#include <ranges>


using i64 = std::int64_t;


constexpr std::pair<int, int> DIRS4[] = {
    { -1, 0 },
    { 0, 1 },
    { 1, 0 },
    { 0, -1 }
};

template<class T, class Comp>
using priority_queue = std::priority_queue<T, std::vector<T>, Comp>;


signed main() {
    int n; std::cin >> n;

    std::vector<i64> h(n * n);
    std::vector<std::string> s(n);
    std::vector<i64> a(n * n), b(n * n);


    for(auto& v : h) std::cin >> v;
    for(auto& v : s) std::cin >> v;

    for(const auto i : std::views::iota(0, n - 1)) {
        for(const auto j : std::views::iota(0, n)) {
            std::cin >> a[i * n + j];
        }
    }

    for(const auto i : std::views::iota(0, n)) {
        for(const auto j : std::views::iota(0, n - 1)) {
            std::cin >> b[i * n + j];
        }
    }


    auto parity = [&](const auto p) {
        return ((p / n) + p % n) % 2;
    };

    std::vector<i64> sup(n * n, -(1UL << 60));
    for(const auto t : std::views::iota(0, 2)) {
        auto cost = [&](const auto p, const auto q, const auto k) {
            const auto r = std::min(p, q);
            const auto w = k % 2 == 0 ? a[r] : b[r];
            const auto x = h[p] + h[q];
            return w * std::abs(x) + ((parity(p) + t) % 2 * 2 - 1) * x;
        };


        priority_queue<std::pair<i64, int>, std::greater<>> que;
        std::vector<i64> dist(n * n, 1UL << 60);


        for(const auto i : std::views::iota(0, n * n)) {
            if(s[i / n][i % n] == '=') {
                que.emplace(dist[i] = 0, i);
            }

            if(parity(i) == t) {
                if(s[i / n][i % n] == '+') que.emplace(dist[i] = 0, i);
            }
            else {
                if(s[i / n][i % n] == '-') que.emplace(dist[i] = 0, i);
            }
        }


        while(!que.empty()) {
            const auto [ d, v ] = que.top(); que.pop();
            if(d > dist[v]) continue;

            const auto i = v / n, j = v % n;

            for(const auto k : std::views::iota(0, 4)) {
                const auto ni = i + DIRS4[k].first, nj = j + DIRS4[k].second;
                if(ni < 0 || nj < 0 || ni >= n || nj >= n) continue;

                const auto nv = ni * n + nj;
                const auto nd = d + cost(v, nv, k);
                if(nd >= dist[nv]) continue;

                que.emplace(dist[nv] = nd, nv);
            }
        }


        for(const auto i : std::views::iota(0, n * n)) {
            const auto v = h[i] + ((parity(i) + t) % 2 * 2 - 1) * dist[i];
            if(sup[i] < v) sup[i] = v;
        }
    }


    int q; std::cin >> q;
    for(const auto _ : std::views::iota(0, q)) {
        int r, c; std::cin >> r >> c; --r, --c;
        i64 e; std::cin >> e;
        std::cout << (sup[r * n + c] >= e ? "Yes" : "No") << "\n";
    }
}
0