結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
kou6839
|
| 提出日時 | 2015-08-04 13:07:55 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 448 ms / 5,000 ms |
| コード長 | 2,055 bytes |
| コンパイル時間 | 2,198 ms |
| コンパイル使用メモリ | 79,684 KB |
| 実行使用メモリ | 59,404 KB |
| 最終ジャッジ日時 | 2024-10-13 05:24:28 |
| 合計ジャッジ時間 | 8,370 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
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[][] d,int[][] map,int n){
while(!que.isEmpty()){
pair now = que.poll();
if ( d[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(d[now.row+dr[i]][now.column+dc[i]]>d[now.row][now.column]+map[now.row+dr[i]][now.column+dc[i]]){
d[now.row+dr[i]][now.column+dc[i]]=d[now.row][now.column]+map[now.row+dr[i]][now.column+dc[i]];
que.add(new pair(d[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 oc = sc.nextInt()-1;
int or = 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];//0,0 スタート
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;
que = new PriorityQueue<>();
que.add(new pair(0,or,oc));
dijkstra(que, d2, map, n);
//System.out.println(Arrays.deepToString(d2));
}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");
}
}
}
kou6839