結果

問題 No.424 立体迷路
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2017-02-04 03:02:53
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,600 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 74,724 KB
実行使用メモリ 56,456 KB
最終ジャッジ日時 2023-08-25 20:04:11
合計ジャッジ時間 7,103 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,204 KB
testcase_01 AC 122 ms
55,868 KB
testcase_02 AC 121 ms
55,876 KB
testcase_03 AC 121 ms
55,944 KB
testcase_04 AC 124 ms
55,852 KB
testcase_05 AC 123 ms
56,076 KB
testcase_06 AC 122 ms
56,088 KB
testcase_07 AC 120 ms
55,852 KB
testcase_08 AC 121 ms
55,780 KB
testcase_09 AC 122 ms
56,456 KB
testcase_10 AC 122 ms
54,356 KB
testcase_11 AC 126 ms
55,696 KB
testcase_12 AC 123 ms
56,248 KB
testcase_13 AC 124 ms
55,912 KB
testcase_14 AC 124 ms
55,872 KB
testcase_15 AC 122 ms
55,856 KB
testcase_16 AC 123 ms
55,716 KB
testcase_17 AC 130 ms
56,100 KB
testcase_18 AC 131 ms
56,168 KB
testcase_19 AC 129 ms
56,248 KB
testcase_20 AC 133 ms
56,196 KB
testcase_21 AC 121 ms
56,112 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 133 ms
55,864 KB
testcase_25 AC 134 ms
55,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int sx = sc.nextInt()-1;
        int sy = sc.nextInt()-1;
        int gx = sc.nextInt()-1;
        int gy = sc.nextInt()-1;
        int [][] Hight = new int [H][W];
        int [][] dist = new int [H][W];
        for(int i=0; i<H; i++){
            String tmp = sc.next();
            for(int j=0; j<W; j++){
                Hight[i][j] = tmp.charAt(j)-'0';
                dist[i][j] = -1;
            }
        }
        Queue<Integer> q = new LinkedList<>();
        int [] dx = {1,0,-1,0};
        int [] dy = {0,1,0,-1};
        q.add(sx);
        q.add(sy);
        dist[sx][sy]=0;
        while(!q.isEmpty()){
            int x = q.poll();
            int y = q.poll();
            if(x==gx&&y==gy){
                System.out.println("YES");
                return;
            }
            for(int k=1; k<=2; k++){
                for(int i=0; i<4; i++){
                    int nx = x+k*dx[i];
                    int ny = y+k*dy[i];
                    if(nx<0||ny<0||nx>=H||ny>=W)continue;
                    if(dist[nx][ny]!=-1)continue;
                    if( (k==1&&Math.abs(Hight[nx][ny]-Hight[x][y])<=1)||(k==2&&Math.abs(Hight[nx][ny]-Hight[x][y])==0) ){
                        dist[nx][ny]=dist[x][y]+1;
                        q.add(nx);
                        q.add(ny);
                    }
                }
            }
        }
        System.out.println("NO");
    }
}
0