結果

問題 No.20 砂漠のオアシス
ユーザー k82bk82b
提出日時 2023-10-10 23:06:27
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 141 ms / 5,000 ms
コード長 1,843 bytes
コンパイル時間 3,239 ms
コンパイル使用メモリ 195,648 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-13 01:28:42
合計ジャッジ時間 4,970 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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;}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0