結果

問題 No.424 立体迷路
ユーザー aaaaasatoriaaaaasatori
提出日時 2018-02-23 18:32:13
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,894 bytes
コンパイル時間 4,292 ms
コンパイル使用メモリ 86,212 KB
実行使用メモリ 42,532 KB
最終ジャッジ日時 2024-04-17 05:46:53
合計ジャッジ時間 8,644 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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");
		}
		
		for(int i = 0;i < h;i++) {
			for(int j = 0;j < w;j++) {
				System.out.print(mapprime[i][j]);
			}
			System.out.println();
		}
	}
}
class Place{
	int x; //縦方向
	int y; //横方向
	Place(int x,int y){
		this.x = x;
		this.y = y;
	}
}
0