結果

問題 No.2826 Earthwork
ユーザー 🦠みどりむし🦠みどりむし
提出日時 2024-06-26 11:10:43
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,127 ms / 5,000 ms
コード長 2,972 bytes
コンパイル時間 1,641 ms
コンパイル使用メモリ 129,660 KB
実行使用メモリ 29,968 KB
最終ジャッジ日時 2024-06-26 11:38:13
合計ジャッジ時間 26,198 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 36 ms
5,376 KB
testcase_02 AC 1,001 ms
29,584 KB
testcase_03 AC 112 ms
5,772 KB
testcase_04 AC 858 ms
25,372 KB
testcase_05 AC 196 ms
8,772 KB
testcase_06 AC 528 ms
17,408 KB
testcase_07 AC 674 ms
21,012 KB
testcase_08 AC 1,001 ms
29,580 KB
testcase_09 AC 1,032 ms
29,840 KB
testcase_10 AC 1,081 ms
29,584 KB
testcase_11 AC 730 ms
29,196 KB
testcase_12 AC 39 ms
5,376 KB
testcase_13 AC 326 ms
11,472 KB
testcase_14 AC 1,127 ms
29,968 KB
testcase_15 AC 250 ms
10,104 KB
testcase_16 AC 457 ms
17,408 KB
testcase_17 AC 165 ms
7,424 KB
testcase_18 AC 414 ms
16,912 KB
testcase_19 AC 185 ms
8,832 KB
testcase_20 AC 851 ms
24,852 KB
testcase_21 AC 38 ms
5,376 KB
testcase_22 AC 705 ms
20,804 KB
testcase_23 AC 665 ms
20,280 KB
testcase_24 AC 1,085 ms
29,712 KB
testcase_25 AC 392 ms
20,916 KB
testcase_26 AC 626 ms
20,864 KB
testcase_27 AC 29 ms
5,376 KB
testcase_28 AC 1,103 ms
29,968 KB
testcase_29 AC 86 ms
5,376 KB
testcase_30 AC 55 ms
5,376 KB
testcase_31 AC 86 ms
5,376 KB
testcase_32 AC 34 ms
5,376 KB
testcase_33 AC 590 ms
18,040 KB
testcase_34 AC 1,049 ms
29,568 KB
testcase_35 AC 240 ms
9,512 KB
testcase_36 AC 1,060 ms
29,968 KB
testcase_37 AC 1,096 ms
29,824 KB
testcase_38 AC 526 ms
16,900 KB
testcase_39 AC 58 ms
5,376 KB
testcase_40 AC 47 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);
        };


        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(parity(i) == t) {
            	if(s[i / n][i % n] == '=') que.emplace(dist[i] = -h[i], i);
                if(s[i / n][i % n] == '+') que.emplace(dist[i] = -h[i], i);
            }
            else {
            	if(s[i / n][i % n] == '=') que.emplace(dist[i] = h[i], i);
                if(s[i / n][i % n] == '-') que.emplace(dist[i] = h[i], 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 = ((parity(i) + t) % 2 * 2 - 1) * dist[i];
            if(sup[i] < v) sup[i] = v;
        }
    }
	
	// for(auto& v : sup) {
	// 	std::cerr << 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