結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
kou6839
|
| 提出日時 | 2014-11-26 01:13:22 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,999 bytes |
| コンパイル時間 | 2,136 ms |
| コンパイル使用メモリ | 79,596 KB |
| 実行使用メモリ | 59,468 KB |
| 最終ジャッジ日時 | 2024-10-13 04:59:47 |
| 合計ジャッジ時間 | 8,044 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 WA * 5 |
ソースコード
import java.math.BigInteger;
import java.util.*;
class pair implements Comparable{
int x;
int y;
int cost;
pair(int x,int y,int cost){
this.x=x;
this.y=y;
this.cost=cost;
}
@Override
public int compareTo(Object o) {
// TODO Auto-generated method stub
pair aaa=(pair)o;
return this.cost-aaa.cost;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] vx ={1,0,-1,0};
int[] vy= {0,1,0,-1};
int n=sc.nextInt();
int hp=sc.nextInt();
int ox=sc.nextInt();
int oy=sc.nextInt();
int[][] edge = new int[n+1][n+1];
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
edge[i][j]=sc.nextInt();
}
}
PriorityQueue<pair> queue = new PriorityQueue<pair>();
int[][] dp = new int[n+1][n+1];
for(int i=1;i<=n;i++){
Arrays.fill(dp[i], Integer.MAX_VALUE);
}
dp[1][1]=0;
queue.add(new pair(1,1,0));
while(!queue.isEmpty()){
pair temp =queue.poll();
if(dp[temp.x][temp.y]<temp.cost) continue;
for(int i=0;i<4;i++){
if(temp.x+vx[i]<1||temp.x+vx[i]>n||temp.y+vy[i]<1||temp.y+vy[i]>n) continue;
int costt = edge[temp.x+vx[i]][temp.y+vy[i]];
if(dp[temp.x+vx[i]][temp.y+vy[i]]>dp[temp.x][temp.y]+costt){
dp[temp.x+vx[i]][temp.y+vy[i]]=dp[temp.x][temp.y]+costt;
queue.add(new pair(temp.x+vx[i],temp.y+vy[i],dp[temp.x+vx[i]][temp.y+vy[i]]));
}
}
}
if(ox!=0&&oy!=0){
int[][] dpp = new int[n+1][n+1];
for(int i=1;i<=n;i++){
Arrays.fill(dpp[i], Integer.MAX_VALUE);
}
dpp[ox][oy]=0;
queue.add(new pair(ox,oy,0));
while(!queue.isEmpty()){
pair temp =queue.poll();
if(dpp[temp.x][temp.y]<temp.cost) continue;
for(int i=0;i<4;i++){
if(temp.x+vx[i]<1||temp.x+vx[i]>n||temp.y+vy[i]<1||temp.y+vy[i]>n) continue;
int costt = edge[temp.x+vx[i]][temp.y+vy[i]];
if(dpp[temp.x+vx[i]][temp.y+vy[i]]>dpp[temp.x][temp.y]+costt){
dpp[temp.x+vx[i]][temp.y+vy[i]]=dpp[temp.x][temp.y]+costt;
queue.add(new pair(temp.x+vx[i],temp.y+vy[i],dpp[temp.x+vx[i]][temp.y+vy[i]]));
}
}
}
if(dp[n][n]<hp){
System.out.println("YES");
return;
}else{
if( (hp-dp[ox][oy])*2>dpp[n][n]){
System.out.println("YES");
return;
}
System.out.println("NO");
}
}
else{
if(dp[n][n]<hp){
System.out.println("YES");
return;
}else{
System.out.println("NO");
return;
}
}
}
}
kou6839