結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
aaaaasatori
|
| 提出日時 | 2018-02-23 18:32:13 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,894 bytes |
| コンパイル時間 | 5,110 ms |
| コンパイル使用メモリ | 83,588 KB |
| 実行使用メモリ | 56,368 KB |
| 最終ジャッジ日時 | 2024-10-08 17:31:48 |
| 合計ジャッジ時間 | 10,176 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 5 |
| other | WA * 21 |
ソースコード
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;
}
}
aaaaasatori