結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
はまやんはまやん
|
| 提出日時 | 2015-06-24 18:02:51 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,603 bytes |
| コンパイル時間 | 2,113 ms |
| コンパイル使用メモリ | 78,360 KB |
| 実行使用メモリ | 112,788 KB |
| 最終ジャッジ日時 | 2024-10-13 05:16:35 |
| 合計ジャッジ時間 | 11,580 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 TLE * 2 -- * 8 |
ソースコード
import java.util.Comparator;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
static int N, L, OX, OY;
static int[][] LL;
static int[][][] cost;
static boolean[][] check;
static int[][] mincost;
static int[] dx = {1, 0, -1, 0};
static int[] dy = {0, 1, 0, -1};
public static void dik(int sx, int sy)
{
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
check[i][j] = false;
mincost[i][j] = Integer.MAX_VALUE / 2;
}
}
PriorityQueue<int[]> queue = new PriorityQueue<int[]>(new Comparator<int[]>() {
public int compare(int[] a, int[] b)
{
int t = mincost[a[1]][a[0]] - mincost[b[1]][b[0]];
if(t > 0)
return 1;
else if(t == 0)
return 0;
else {
return -1;
}
}
});
mincost[sy][sx] = 0;
queue.offer(new int[]{sx, sy});
while (!queue.isEmpty()) {
int[] q = queue.poll();
int x = q[0];
int y = q[1];
check[y][x] = true;
for (int i = 0; i < 4; i++) {
int xx = x + dx[i];
int yy = y + dy[i];
if( !(0 <= xx && xx <= N-1) ) continue;
if( !(0 <= yy && yy <= N-1) ) continue;
if(check[yy][xx] == true) continue;
mincost[yy][xx] = Math.min(mincost[yy][xx], mincost[y][x] + cost[y][x][i]);
if(!queue.contains(new int[]{xx, yy})) queue.offer(new int[]{xx, yy});
}
}
}
public static int solve(){
cost = new int[N][N][4];
check = new boolean[N][N];
mincost = new int[N][N];
for (int y = 0; y < N; y++) {
for (int x = 0; x < N; x++) {
for (int i = 0; i < 4; i++) {
int xx = x + dx[i];
int yy = y + dy[i];
if( !(0 <= xx && xx <= N-1) || !(0 <= yy && yy <= N-1) )
{
cost[y][x][i] = Integer.MAX_VALUE / 2;
continue;
}
cost[y][x][i] = LL[yy][xx];
}
}
}
dik(0, 0);
int stog = mincost[N-1][N-1];
if(stog < L)
{
System.out.println("YES");
return 0;
}
if(OX == 0 && OY == 0)
{
System.out.println("NO");
return 0;
}
int stoo = mincost[OY-1][OX-1];
dik(OX-1, OY-1);
int otog = mincost[N-1][N-1];
if(stoo >= L)
{
System.out.println("NO");
return 0;
}
L = (L - stoo) * 2;
if(otog >= L)
{
System.out.println("NO");
return 0;
}
System.out.println("YES");
return 0;
}
public static void main(String[] args){
Scanner S = new Scanner(System.in);
N = S.nextInt();
L = S.nextInt();
OX = S.nextInt();
OY = S.nextInt();
LL = new int[N][N];
for (int y = 0; y < N; y++) {
for (int x = 0; x < N; x++) {
LL[y][x] = S.nextInt();
}
}
solve();
}
}
はまやんはまやん