結果
| 問題 | No.20 砂漠のオアシス | 
| コンテスト | |
| ユーザー |  kou6839 | 
| 提出日時 | 2015-08-04 12:57:27 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,989 bytes | 
| コンパイル時間 | 2,095 ms | 
| コンパイル使用メモリ | 79,632 KB | 
| 実行使用メモリ | 60,676 KB | 
| 最終ジャッジ日時 | 2024-10-13 05:24:12 | 
| 合計ジャッジ時間 | 8,189 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 WA * 5 | 
ソースコード
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");
		}
	}
}
            
            
            
        