結果

問題 No.20 砂漠のオアシス
ユーザー kou6839kou6839
提出日時 2015-08-04 12:57:27
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,989 bytes
コンパイル時間 2,336 ms
コンパイル使用メモリ 79,364 KB
実行使用メモリ 58,596 KB
最終ジャッジ日時 2024-04-21 06:41:42
合計ジャッジ時間 7,867 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
41,432 KB
testcase_01 AC 122 ms
41,172 KB
testcase_02 AC 124 ms
41,648 KB
testcase_03 AC 191 ms
43,944 KB
testcase_04 AC 190 ms
44,460 KB
testcase_05 AC 360 ms
48,012 KB
testcase_06 AC 432 ms
48,196 KB
testcase_07 AC 387 ms
46,756 KB
testcase_08 AC 443 ms
48,364 KB
testcase_09 AC 444 ms
48,136 KB
testcase_10 WA -
testcase_11 AC 113 ms
41,080 KB
testcase_12 WA -
testcase_13 AC 191 ms
43,884 KB
testcase_14 AC 218 ms
45,776 KB
testcase_15 AC 194 ms
44,476 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 242 ms
47,372 KB
testcase_20 AC 176 ms
42,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;


class pair implements Comparable<pair>{
	int cost;
	int row,column;
	pair(int cost,int row,int column){
		this.cost=cost;
		this.row = row;
		this.column = column;
	}
	@Override
	public int compareTo(pair o) {
		// TODO Auto-generated method stub
		return this.cost-o.cost;
	}
}
public class Main {
	static void dijkstra(PriorityQueue<pair> que,int[][] d1,int[][] map,int n){
		while(!que.isEmpty()){
			pair now = que.poll();
			if ( d1[now.row][now.column]<now.cost) continue;
			for(int i=0;i<4;i++){
				if( now.row+dr[i]>=0 && now.row+dr[i]<n && now.column+dc[i]>=0 && now.column+dc[i]<n){
					if(d1[now.row+dr[i]][now.column+dc[i]]>d1[now.row][now.column]+map[now.row+dr[i]][now.column+dc[i]]){
						d1[now.row+dr[i]][now.column+dc[i]]=d1[now.row][now.column]+map[now.row+dr[i]][now.column+dc[i]];
						que.add(new pair(d1[now.row+dr[i]][now.column+dc[i]], now.row+dr[i],now.column+dc[i]));
					}
				}
			}
		}
	}
	static int[] dr ={1,0,-1,0};
	static int[] dc ={0,1,0,-1};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int v = sc.nextInt();
		int or = sc.nextInt()-1;
		int oc = sc.nextInt()-1;
		int[][] map = new int[n][n];
		for(int i=0;i<n;i++) for(int j=0;j<n;j++) map[i][j]=sc.nextInt();
		int[][] d1 = new int[n][n];
		int[][] d2 = new int[n][n];
		for(int i=0;i<n;i++) Arrays.fill(d1[i], 1000000);
		for(int i=0;i<n;i++) Arrays.fill(d2[i], 1000000);
		d1[0][0]=0;

		PriorityQueue<pair> que = new PriorityQueue<>();
		que.add(new pair(0, 0, 0));
		dijkstra(que, d1, map, n);
		if(or!=-1&&oc!=-1){
			d2[or][oc]=0;
			PriorityQueue<pair> que1 = new PriorityQueue<>();
			que1.add(new pair(0,or,oc));
			dijkstra(que1, d2, map, n);
		}else{
			if(d1[n-1][n-1]<v){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
			return;
		}
		if(d1[n-1][n-1]<v || d2[n-1][n-1]<2*(v-d1[or][oc])){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
}
0