結果

問題 No.2826 Earthwork
ユーザー NachiaNachia
提出日時 2024-07-26 23:50:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,133 ms / 5,000 ms
コード長 3,346 bytes
コンパイル時間 1,473 ms
コンパイル使用メモリ 112,244 KB
実行使用メモリ 94,544 KB
最終ジャッジ日時 2024-07-26 23:50:54
合計ジャッジ時間 24,099 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 17 ms
5,376 KB
testcase_02 AC 1,133 ms
93,904 KB
testcase_03 AC 86 ms
12,056 KB
testcase_04 AC 741 ms
79,864 KB
testcase_05 AC 139 ms
22,804 KB
testcase_06 AC 505 ms
51,960 KB
testcase_07 AC 676 ms
64,596 KB
testcase_08 AC 1,044 ms
94,032 KB
testcase_09 AC 1,022 ms
94,372 KB
testcase_10 AC 923 ms
94,036 KB
testcase_11 AC 633 ms
93,696 KB
testcase_12 AC 17 ms
5,376 KB
testcase_13 AC 279 ms
32,172 KB
testcase_14 AC 1,027 ms
94,416 KB
testcase_15 AC 226 ms
26,224 KB
testcase_16 AC 372 ms
52,104 KB
testcase_17 AC 133 ms
16,976 KB
testcase_18 AC 355 ms
50,432 KB
testcase_19 AC 144 ms
22,816 KB
testcase_20 AC 832 ms
77,892 KB
testcase_21 AC 14 ms
6,940 KB
testcase_22 AC 642 ms
62,752 KB
testcase_23 AC 576 ms
61,808 KB
testcase_24 AC 950 ms
94,032 KB
testcase_25 AC 268 ms
64,512 KB
testcase_26 AC 608 ms
63,216 KB
testcase_27 AC 8 ms
5,376 KB
testcase_28 AC 1,067 ms
94,544 KB
testcase_29 AC 53 ms
10,876 KB
testcase_30 AC 30 ms
6,944 KB
testcase_31 AC 59 ms
9,856 KB
testcase_32 AC 14 ms
6,940 KB
testcase_33 AC 536 ms
52,740 KB
testcase_34 AC 947 ms
93,996 KB
testcase_35 AC 231 ms
25,156 KB
testcase_36 AC 991 ms
94,420 KB
testcase_37 AC 1,022 ms
94,400 KB
testcase_38 AC 487 ms
48,740 KB
testcase_39 AC 30 ms
7,552 KB
testcase_40 AC 25 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <array>
#include <cmath>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
#define repr(i,n) for(int i=int(n)-1; i>=0; i--)
const i64 INF = 1001001001001001001 * 4;
const char* yn(bool x){ return x ? "Yes" : "No"; }
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
template<typename A> using nega_queue = std::priority_queue<A,std::vector<A>,std::greater<A>>;
template<class R> auto ComparingBy(R f){ return [g=std::move(f)](auto l, auto r) -> bool { return g(l) < g(r); }; }
#include <atcoder/modint>
using Modint = atcoder::static_modint<998244353>;
using namespace std;

void testcase(){
    i64 N; cin >> N;
    vector<i64> H(N*N);
    rep(i,N*N) cin >> H[i];
    vector<int> ud(N*N);
    rep(i,N){
        string x; cin >> x;
        rep(j,N) ud[i*N+j] = int(string("=+-?").find(x[j]));
    }
    vector<i64> A(N*N), B(N*N);
    rep(i,N-1) rep(j,N){ i64 a; cin >> a; A[i*N+j] = a * abs(H[i*N+j] + H[i*N+j+N]); }
    rep(i,N) rep(j,N-1){ i64 a; cin >> a; B[i*N+j] = a * abs(H[i*N+j] + H[i*N+j+1]); }
    i64 Q; cin >> Q;
    vector<int> parity(N*N);
    rep(i,N) rep(j,N) parity[i*N+j] = (i+j)%2;
    struct Query { i64 i; i64 e; i64 parity; i64 ans; };
    vector<Query> queries(Q);
    rep(i,Q){
        i64 r,c,e; cin >> r >> c >> e; r--; c--;
        queries[i] = { r*N+c, e-H[r*N+c], (r+c)%2, 0 };
    }
    rep(t,2){
        vector<vector<pair<i64,i64>>> adj(N*N);
        rep(i,N) rep(j,N){
            i64 p = i * N + j;
            if(j != N-1){
                i64 d = H[p] + H[p+1]; if(parity[p]) d = -d;
                adj[p].push_back({ p+1, B[p] + d });
                adj[p+1].push_back({ p, B[p] - d });
            }
            if(i != N-1){
                i64 d = H[p] + H[p+N]; if(parity[p]) d = -d;
                adj[p].push_back({ p+N, A[p] + d });
                adj[p+N].push_back({ p, A[p] - d });
            }
        }
        vector<i64> dist(N*N, INF);
        nega_queue<pair<i64,i64>> que;
        auto see = [&](i64 p, i64 d){
            if(dist[p] <= d) return;
            dist[p] = d;
            que.push({ d, p });
        };
        rep(i,N*N) if(!(ud[i] & (1 << parity[i]))) see(i, 0);
        while(que.size()){
            auto [d,p] = que.top(); que.pop();
            if(dist[p] != d) continue;
            for(auto [to,e] : adj[p]){
                //cout << "p = " << p << " , to = " << to << " , e = " << e << endl;
                see(to, d+e);
            }
        }
        //rep(i,N){ rep(j,N){
        //    i64 h = dist[i*N+j];
        //    if(parity[i*N+j]) h *= -1;
        //    h += H[i*N+j];
        //    cout << h << " ";
        //} cout << endl; }
        for(auto& q : queries) if(q.parity == t){
            //cout << "dist = " << dist[q.i] << endl;
            //cout << "e = " << q.e << endl;
            q.ans = (q.e <= dist[q.i] ? 1 : 0);
        }
        rep(i,N*N) parity[i] ^= 1;
    }
    rep(i,Q) cout << yn(queries[i].ans) << '\n';
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    testcase();
    return 0;
}
0