結果

問題 No.424 立体迷路
ユーザー atkrymatkrym
提出日時 2016-10-19 15:39:22
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,908 bytes
コンパイル時間 2,458 ms
コンパイル使用メモリ 78,052 KB
実行使用メモリ 41,728 KB
最終ジャッジ日時 2024-05-02 05:35:22
合計ジャッジ時間 6,905 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
41,132 KB
testcase_01 AC 134 ms
41,304 KB
testcase_02 AC 115 ms
39,668 KB
testcase_03 AC 131 ms
41,260 KB
testcase_04 AC 137 ms
41,000 KB
testcase_05 AC 135 ms
41,364 KB
testcase_06 AC 133 ms
41,424 KB
testcase_07 AC 119 ms
39,968 KB
testcase_08 AC 132 ms
41,148 KB
testcase_09 AC 128 ms
41,348 KB
testcase_10 AC 114 ms
39,760 KB
testcase_11 AC 123 ms
40,684 KB
testcase_12 AC 129 ms
41,160 KB
testcase_13 AC 116 ms
39,936 KB
testcase_14 AC 116 ms
39,932 KB
testcase_15 AC 137 ms
41,196 KB
testcase_16 AC 120 ms
40,108 KB
testcase_17 AC 139 ms
41,400 KB
testcase_18 AC 139 ms
41,168 KB
testcase_19 AC 146 ms
41,316 KB
testcase_20 AC 140 ms
41,316 KB
testcase_21 AC 131 ms
41,032 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 139 ms
41,548 KB
testcase_25 AC 157 ms
41,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    private static int h;
    private static int w;
    private static int sx;
    private static int sy;
    private static int ex;
    private static int ey;
    private static int[][] ary;
    private static boolean[][] is;
    public static void main(String[] args) throws Exception {
        h = sc.nextInt();
        w = sc.nextInt();
        sx = sc.nextInt()-1;
        sy = sc.nextInt()-1;
        ex = sc.nextInt()-1;
        ey = sc.nextInt()-1;
        
        ary = new int[h][w];
        is = new boolean[h][w];
        
        for (int i = 0;i < h;i++) {
            String s = sc.next();
            for (int j = 0;j < w;j++) {
                ary[i][j] = Integer.parseInt(s.substring(j, j+1));
            }
        }
        
        if (move(sx, sy)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
    
    private static boolean move(int x, int y) {
        
        if (x == ex && y == ey) return true;
        int[] dx = {-1, 0, 1, 0, -2, 0, 2, 0};
        int[] dy = {0, 1, 0, -1, 0, 2, 0, -2};
        
        int height = ary[x][y];
        is[x][y] = true;
        
        for (int i = 0;i < 8;i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (0 <= nx && nx < h && 0 <= ny && ny < w && !is[nx][ny]) {
                int nheight = ary[nx][ny];
                boolean m = false;
                if (i < 4) {
                    m = (height-1 <= nheight && nheight <= height+1);
                } else {
                    m = (height == nheight);
                }
                
                if (m) {
                    if (move(nx, ny)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
}
0