結果

問題 No.1638 Robot Maze
ユーザー Example0911Example0911
提出日時 2021-08-06 21:36:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,957 bytes
コンパイル時間 2,357 ms
コンパイル使用メモリ 214,108 KB
実行使用メモリ 6,836 KB
最終ジャッジ日時 2023-10-17 02:53:42
合計ジャッジ時間 3,936 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,956 KB
testcase_01 AC 3 ms
5,956 KB
testcase_02 AC 4 ms
5,952 KB
testcase_03 AC 7 ms
6,836 KB
testcase_04 AC 4 ms
5,960 KB
testcase_05 AC 3 ms
5,960 KB
testcase_06 AC 4 ms
5,960 KB
testcase_07 AC 4 ms
5,960 KB
testcase_08 AC 4 ms
5,960 KB
testcase_09 AC 4 ms
5,960 KB
testcase_10 AC 3 ms
5,960 KB
testcase_11 AC 3 ms
5,960 KB
testcase_12 AC 4 ms
5,964 KB
testcase_13 AC 4 ms
5,960 KB
testcase_14 AC 6 ms
6,432 KB
testcase_15 AC 4 ms
6,264 KB
testcase_16 AC 5 ms
6,264 KB
testcase_17 AC 5 ms
6,264 KB
testcase_18 AC 4 ms
6,264 KB
testcase_19 AC 4 ms
6,264 KB
testcase_20 AC 5 ms
6,264 KB
testcase_21 AC 4 ms
6,288 KB
testcase_22 AC 4 ms
6,288 KB
testcase_23 AC 4 ms
6,288 KB
testcase_24 AC 4 ms
6,288 KB
testcase_25 AC 5 ms
6,288 KB
testcase_26 AC 4 ms
6,288 KB
testcase_27 AC 4 ms
6,288 KB
testcase_28 AC 4 ms
6,288 KB
testcase_29 AC 4 ms
6,288 KB
testcase_30 AC 4 ms
5,956 KB
testcase_31 AC 3 ms
5,956 KB
testcase_32 AC 6 ms
6,540 KB
testcase_33 AC 7 ms
6,616 KB
testcase_34 AC 7 ms
6,724 KB
testcase_35 AC 6 ms
6,616 KB
testcase_36 AC 6 ms
6,728 KB
testcase_37 AC 5 ms
6,544 KB
testcase_38 AC 6 ms
6,540 KB
testcase_39 AC 6 ms
6,708 KB
testcase_40 AC 6 ms
6,564 KB
testcase_41 AC 6 ms
6,624 KB
testcase_42 AC 6 ms
6,636 KB
testcase_43 AC 6 ms
6,628 KB
testcase_44 AC 6 ms
6,648 KB
testcase_45 AC 6 ms
6,632 KB
testcase_46 AC 6 ms
6,688 KB
testcase_47 AC 6 ms
6,608 KB
testcase_48 AC 7 ms
6,724 KB
testcase_49 AC 6 ms
6,544 KB
testcase_50 AC 6 ms
6,632 KB
testcase_51 AC 7 ms
6,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

#define int long long

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 1000000007;
int N, M;
vector<pair<ll, ll>>edge[100010];

vector<ll> dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>pq;
	vector<ll>dist(N * M, INF);
	dist[s] = 0;
	pq.push({ dist[s],s });
	while (!pq.empty()) {
		P p = pq.top(); pq.pop();
		ll d = p.first, from = p.second;
		if (dist[from] < d)continue;
		for (auto nv : edge[from]) {
			ll to = nv.first; ll cost = nv.second;
			if (dist[from] + cost < dist[to]) {
				dist[to] = dist[from] + cost;
				pq.push({ dist[to],to });
			}
		}
	}
	return dist;
}

int f(int i, int j) {
	return i * M + j;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> M;
	int U, D, R, L, K, p; cin >> U >> D >> R >> L >> K >> p;
	int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; sx--; sy--; gx--; gy--;
	vector<vector<char>>C(N, vector<char>(M));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> C[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (C[i][j] == '#')continue;
			int cost = 0;
			// i - 1
			if (i > 0 && C[i - 1][j] != '#') {
				cost = U;
				if (C[i - 1][j] == '@')cost += p;
				edge[f(i, j)].push_back({ f(i - 1, j), cost });

			}
			// i + 1
			if (i < N - 1 && C[i + 1][j] != '#') {
				cost = D;
				if (C[i + 1][j] == '@')cost += p;
				edge[f(i, j)].push_back({ f(i + 1, j), cost });
			}
			// j + 1
			if (j < M - 1 && C[i][j + 1] != '#') {
				cost = R;
				if (C[i][j + 1] == '@')cost += p;
				edge[f(i, j)].push_back({ f(i, j + 1), cost });
			}
			// j - 1
			if (j > 0 && C[i][j - 1] != '#') {
				cost = L;
				if (C[i][j - 1] == '@')cost += p;
				edge[f(i, j)].push_back({ f(i, j - 1), cost });
			}
		}
	}
	auto d = dijkstra(f(sx, sy));
	int ans = d[f(gx, gy)];
	if (ans <= K)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;

}

0