結果

問題 No.2826 Earthwork
ユーザー NachiaNachia
提出日時 2024-07-26 23:44:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,144 bytes
コンパイル時間 1,575 ms
コンパイル使用メモリ 112,892 KB
実行使用メモリ 273,652 KB
最終ジャッジ日時 2024-07-26 23:44:51
合計ジャッジ時間 25,199 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 136 ms
22,708 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 615 ms
93,716 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 331 ms
51,984 KB
testcase_17 WA -
testcase_18 AC 318 ms
50,304 KB
testcase_19 AC 128 ms
22,856 KB
testcase_20 WA -
testcase_21 AC 13 ms
5,632 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 260 ms
64,488 KB
testcase_26 WA -
testcase_27 AC 8 ms
5,376 KB
testcase_28 WA -
testcase_29 AC 47 ms
10,868 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

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-1){
            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]){
                see(to, d+e);
            }
        }
        //rep(i,N){ rep(j,N){ cout << dist[i*N+j] << " "; } 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