結果

問題 No.20 砂漠のオアシス
ユーザー atn112323atn112323
提出日時 2016-05-06 11:36:31
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,361 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 65,696 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 06:53:05
合計ジャッジ時間 1,674 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 11 ms
5,376 KB
testcase_06 AC 8 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 9 ms
5,376 KB
testcase_09 AC 13 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 3 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 4 ms
5,376 KB
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <utility>

using namespace std;

const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};
const int INF = 1000000;

int N, V, OX, OY;
int L[202][202];
int dist[202][202];

void bfs(int sx, int sy) {
	for (int i = 0; i < N + 2; i++) {
		for (int j = 0; j < N + 2; j++) {
			dist[i][j] = V + 1;
		}
	}
	priority_queue<pair<int, int> > P;
	P.push(make_pair(0, 1 + 1 * (N + 2)));
	dist[1][1] = 0;
	while (!P.empty()) {
		pair<int, int> p = P.top();
		P.pop();
		int x = p.second % (N + 2), y = p.second / (N + 2);
		if (-p.first > dist[x][y]) {
			continue;
		}
		for (int d = 0; d < 4; d++) {
			int xx = x + DX[d], yy = y + DY[d];
			if (dist[x][y] + L[xx][yy] < dist[xx][yy]) {
				dist[xx][yy] = dist[x][y] + L[xx][yy];
				P.push(make_pair(-dist[xx][yy], xx + yy * (N + 2)));
			}
		}
	}
}

int main() {
	cin >> N >> V >> OX >> OY;
	for (int i = 0; i < N + 2; i++) {
		for (int j = 0; j < N + 2; j++) {
			L[i][j] = INF;
		}
	}
	for (int y = 0; y < N; y++) {
		for (int x = 0; x < N; x++) {
			cin >> L[x + 1][y + 1];
		}
	}
	bfs(1, 1);
	if (dist[N][N] <= V) {
		cout << "YES" << endl;
	} else if (dist[OX][OY] <= V) {
		V -= dist[OX][OY];
		V *= 2;
		bfs(OX, OY);
		if (dist[N][N] <= V) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	} else {
		cout << "NO" << endl;
	}
	return 0;
}
0