結果

問題 No.2826 Earthwork
ユーザー achapiachapi
提出日時 2024-07-26 11:26:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,500 ms / 5,000 ms
コード長 2,425 bytes
コンパイル時間 2,886 ms
コンパイル使用メモリ 229,028 KB
実行使用メモリ 157,648 KB
最終ジャッジ日時 2024-07-26 11:27:25
合計ジャッジ時間 34,771 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 42 ms
6,940 KB
testcase_02 AC 1,361 ms
156,980 KB
testcase_03 AC 148 ms
17,624 KB
testcase_04 AC 1,104 ms
133,324 KB
testcase_05 AC 257 ms
36,096 KB
testcase_06 AC 682 ms
85,336 KB
testcase_07 AC 893 ms
107,324 KB
testcase_08 AC 1,322 ms
157,024 KB
testcase_09 AC 1,366 ms
157,360 KB
testcase_10 AC 1,412 ms
157,096 KB
testcase_11 AC 1,012 ms
156,708 KB
testcase_12 AC 41 ms
6,940 KB
testcase_13 AC 448 ms
51,636 KB
testcase_14 AC 1,500 ms
157,604 KB
testcase_15 AC 320 ms
41,820 KB
testcase_16 AC 619 ms
86,004 KB
testcase_17 AC 200 ms
25,936 KB
testcase_18 AC 536 ms
83,096 KB
testcase_19 AC 239 ms
36,092 KB
testcase_20 AC 1,099 ms
129,380 KB
testcase_21 AC 42 ms
6,944 KB
testcase_22 AC 888 ms
104,040 KB
testcase_23 AC 860 ms
102,600 KB
testcase_24 AC 1,349 ms
157,148 KB
testcase_25 AC 532 ms
107,280 KB
testcase_26 AC 845 ms
104,824 KB
testcase_27 AC 28 ms
6,944 KB
testcase_28 AC 1,423 ms
157,648 KB
testcase_29 AC 102 ms
15,592 KB
testcase_30 AC 58 ms
8,480 KB
testcase_31 AC 97 ms
14,092 KB
testcase_32 AC 35 ms
6,940 KB
testcase_33 AC 752 ms
86,496 KB
testcase_34 AC 1,367 ms
157,020 KB
testcase_35 AC 312 ms
39,988 KB
testcase_36 AC 1,412 ms
157,600 KB
testcase_37 AC 1,431 ms
157,376 KB
testcase_38 AC 668 ms
79,892 KB
testcase_39 AC 65 ms
9,908 KB
testcase_40 AC 52 ms
7,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;template<class T> vector<T> Dijkstra(vector<vector<pair<int, T>>> &G, int s){
	vector<T> D(G.size(), 4e18);
	D[s] = 0;
	priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;
	q.push(make_pair(0, s));
	while (!q.empty()){
		auto [d, u] = q.top();
		q.pop();
		if (D[u] < d){
			continue;
		}
		for (auto [v, c] : G[u]){
			d = D[u] + c;
			if (d < D[v]){
				D[v] = d;
				q.push(make_pair(d, v));
			}
		}
	}
	return D;
}
int main(){
	int N;
	cin >> N;
	vector<vector<int>> H(N, vector<int>(N));
	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++){
			cin >> H[i][j];
		}
	}
	vector<string> S(N);
	for (int i = 0; i < N; i++){
		cin >> S[i];
	}
	vector<vector<long long>> A(N - 1, vector<long long>(N));
	for (int i = 0; i < N - 1; i++){
		for (int j = 0; j < N; j++){
			cin >> A[i][j];
		}
	}
	vector<vector<long long>> B(N, vector<long long>(N - 1));
	for (int i = 0; i < N; i++){
		for (int j = 0; j < N - 1; j++){
			cin >> B[i][j];
		}
	}
	vector<vector<vector<pair<int, long long>>>> G(2, vector<vector<pair<int, long long>>>(N * N + 1));
	vector<vector<long long>> D(2);
	for (int k = 0; k < 2; k++){
		for (int i = 0; i < N - 1; i++){
			for (int j = 0; j < N; j++){
				long long T = (H[i][j] + H[i + 1][j]) * (1 - (i + j + k) % 2 * 2);
				G[k][i * N + j].push_back(make_pair((i + 1) * N + j, abs(T) * A[i][j] + T));
				G[k][(i + 1) * N + j].push_back(make_pair(i * N + j, abs(T) * A[i][j] - T));
			}
		}
		for (int i = 0; i < N; i++){
			for (int j = 0; j < N - 1; j++){
				long long T = (H[i][j] + H[i][j + 1]) * (1 - (i + j + k) % 2 * 2);
				G[k][i * N + j].push_back(make_pair(i * N + j + 1, abs(T) * B[i][j] + T));
				G[k][i * N + j + 1].push_back(make_pair(i * N + j, abs(T) * B[i][j] - T));
			}
		}
		for (int i = 0; i < N; i++){
			for (int j = 0; j < N; j++){
				if (S[i][j] == '?'){
					continue;
				}
				if (S[i][j] == '=' or ((S[i][j] == '-') ^ (i + j + k) % 2) == 0){
					G[k][i * N + j].push_back(make_pair(N * N, 0));
				}
				if (S[i][j] == '=' or ((S[i][j] == '-') ^ (i + j + k) % 2) == 1){
					G[k][N * N].push_back(make_pair(i * N + j, 0));
				}
			}
		}
		D[k] = Dijkstra(G[k], N * N);
	}
	int Q;
	cin >> Q;
	while (Q--){
		int R, C;
		long long E;
		cin >> R >> C >> E;
		R--;
		C--;
		if (D[(R + C) % 2][R * N + C] + H[R][C] >= E){
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
}
0