結果

問題 No.20 砂漠のオアシス
ユーザー k82bk82b
提出日時 2023-10-10 23:06:27
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 146 ms / 5,000 ms
コード長 1,843 bytes
コンパイル時間 3,132 ms
コンパイル使用メモリ 183,032 KB
実行使用メモリ 5,624 KB
最終ジャッジ日時 2023-10-10 23:06:32
合計ジャッジ時間 3,774 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 5 ms
4,348 KB
testcase_04 AC 8 ms
4,388 KB
testcase_05 AC 135 ms
5,624 KB
testcase_06 AC 146 ms
5,328 KB
testcase_07 AC 146 ms
5,220 KB
testcase_08 AC 99 ms
5,224 KB
testcase_09 AC 146 ms
5,192 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 8 ms
4,396 KB
testcase_13 AC 9 ms
4,372 KB
testcase_14 AC 16 ms
4,432 KB
testcase_15 AC 11 ms
4,448 KB
testcase_16 AC 30 ms
4,408 KB
testcase_17 AC 22 ms
4,392 KB
testcase_18 AC 26 ms
4,440 KB
testcase_19 AC 31 ms
4,448 KB
testcase_20 AC 5 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main() {
	enum INF = 10 ^^ 9;
	alias Entry = Tuple!(int, "c", int, "x", int, "y");
	enum dx = [1, 0, -1, 0];
	enum dy = [0, 1, 0, -1];
	const N = readInt;
	const V = readInt;
	int Ox = readInt;
	int Oy = readInt;
	swap(Ox, Oy);
	auto G = new int[][](N, N);
	foreach (i; 0 .. N) foreach (j; 0 .. N) {
		G[i][j] = readInt;
	}
	int dis(int sx, int sy, int gx, int gy) {
		auto dist = new int[][](N, N);
		foreach (i; 0 .. N) foreach (j; 0 .. N) dist[i][j] = INF;
		dist[sx][sy] = 0;
		auto Q = new BinaryHeap!(Array!Entry, "a > b");
		Q.insert(Entry(0, sx, sy));
		while (!Q.empty) {
			int c = Q.front.c;
			int x = Q.front.x;
			int y = Q.front.y;
			Q.removeFront;
			foreach (i; 0 .. 4) {
				int nx = x + dx[i];
				int ny = y + dy[i];
				if (nx < 0 || ny < 0 || nx >= N || ny >= N) continue;
				if (chmin(dist[nx][ny], dist[x][y] + G[nx][ny])) {
					Q.insert(Entry(dist[nx][ny], nx, ny));
				}
			}
		}
		return dist[gx][gy];
	}
	bool ans = dis(0, 0, N - 1, N - 1) < V;
	if (Ox) {
		Ox--, Oy--;
		int x = dis(0, 0, Ox, Oy);
		if (x < V) {
			ans = ans || dis(Ox, Oy, N - 1, N - 1) < (V - x) * 2;
		}
	}
	writeln(ans ? "YES" : "NO");
}

import std,core.bitop;
string[]_R;
string readString(){while(_R.empty){_R=readln.chomp.split;}auto ret=_R.front;_R.popFront;return ret;}
int readInt(){return readString.to!int;}
long readLong(){return readString.to!long;}
ulong readULong(){return readString.to!ulong;}
real readReal(){return readString.to!real;}
bool chmin(T)(ref T A,T B){if(A>B){A=B;return true;}else{return false;}}
bool chmax(T)(ref T A,T B){if(A<B){A=B;return true;}else{return false;}}
int lowerBound(T)(T[]A,T x){int L=-1,R=cast(int)A.length;while(R-L>1){int mid=(L+R)/2;(A[mid]<x?L:R)=mid;}return R;}
int upperBound(T)(T[]A,T x){int L=-1,R=cast(int)A.length;while(R-L>1){int mid=(L+R)/2;(A[mid]<=x?L:R)=mid;}return R;}
0