結果
問題 | No.424 立体迷路 |
ユーザー | aaaaasatori |
提出日時 | 2018-02-23 18:32:46 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 151 ms / 2,000 ms |
コード長 | 1,760 bytes |
コンパイル時間 | 3,838 ms |
コンパイル使用メモリ | 79,780 KB |
実行使用メモリ | 56,340 KB |
最終ジャッジ日時 | 2023-09-18 17:03:51 |
合計ジャッジ時間 | 8,782 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 134 ms
55,732 KB |
testcase_01 | AC | 133 ms
55,868 KB |
testcase_02 | AC | 136 ms
56,084 KB |
testcase_03 | AC | 133 ms
55,792 KB |
testcase_04 | AC | 136 ms
56,040 KB |
testcase_05 | AC | 134 ms
55,824 KB |
testcase_06 | AC | 133 ms
55,632 KB |
testcase_07 | AC | 134 ms
56,340 KB |
testcase_08 | AC | 135 ms
56,288 KB |
testcase_09 | AC | 135 ms
55,988 KB |
testcase_10 | AC | 131 ms
56,040 KB |
testcase_11 | AC | 132 ms
56,016 KB |
testcase_12 | AC | 132 ms
56,012 KB |
testcase_13 | AC | 134 ms
55,976 KB |
testcase_14 | AC | 135 ms
55,900 KB |
testcase_15 | AC | 135 ms
55,872 KB |
testcase_16 | AC | 135 ms
56,044 KB |
testcase_17 | AC | 146 ms
55,932 KB |
testcase_18 | AC | 147 ms
55,528 KB |
testcase_19 | AC | 144 ms
55,788 KB |
testcase_20 | AC | 146 ms
55,816 KB |
testcase_21 | AC | 138 ms
55,540 KB |
testcase_22 | AC | 135 ms
55,780 KB |
testcase_23 | AC | 132 ms
55,532 KB |
testcase_24 | AC | 148 ms
56,152 KB |
testcase_25 | AC | 151 ms
55,920 KB |
ソースコード
import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class No424 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int h = sc.nextInt(); int w = sc.nextInt(); Place start = new Place(sc.nextInt()-1,sc.nextInt()-1); Place goal = new Place(sc.nextInt()-1,sc.nextInt()-1); int map[][] = new int[h][w]; for(int i = 0;i < h;i++) { String s = sc.next(); for(int j = 0;j < w;j++) { map[i][j] = Integer.parseInt("" + s.charAt(j)); } } int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; int dx2[] = {2,0,-2,0}; int dy2[] = {0,2,0,-2}; int mapprime[][] = new int[h][w]; //0なら到達不可能,1なら到達可能 mapprime[start.x][start.y] = 1; Queue<Place> que = new LinkedList<Place>(); que.offer(start); while(que.size() > 0) { Place cplace = que.poll(); for(int i = 0;i < 4;i++) { int x1 = cplace.x + dx[i]; int y1 = cplace.y + dy[i]; int x2 = cplace.x + dx2[i]; int y2 = cplace.y + dy2[i]; if(x1 >= 0 && x1 < h && y1 >= 0 && y1 < w && mapprime[x1][y1] == 0) { if(Math.abs(map[cplace.x][cplace.y] - map[x1][y1]) == 1 || Math.abs(map[cplace.x][cplace.y] - map[x1][y1]) == 0) { mapprime[x1][y1] = 1; que.offer(new Place(x1,y1)); } } if(x2 >= 0 && x2 < h && y2 >= 0 && y2 < w && mapprime[x2][y2] == 0) { if(map[cplace.x][cplace.y] == map[x2][y2] && map[x2][y2] > map[x1][y1]) { mapprime[x2][y2] = 1; que.offer(new Place(x2,y2)); } } } } if(mapprime[goal.x][goal.y] == 1) { System.out.println("YES"); }else { System.out.println("NO"); } } } class Place{ int x; //縦方向 int y; //横方向 Place(int x,int y){ this.x = x; this.y = y; } }