結果
問題 | No.323 yuki国 |
ユーザー | kusagame12 |
提出日時 | 2023-11-26 19:26:55 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 418 ms / 5,000 ms |
コード長 | 3,271 bytes |
コンパイル時間 | 3,015 ms |
コンパイル使用メモリ | 86,880 KB |
実行使用メモリ | 52,328 KB |
最終ジャッジ日時 | 2024-09-26 11:51:53 |
合計ジャッジ時間 | 11,554 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
38,128 KB |
testcase_01 | AC | 72 ms
37,928 KB |
testcase_02 | AC | 68 ms
38,384 KB |
testcase_03 | AC | 99 ms
42,128 KB |
testcase_04 | AC | 77 ms
38,440 KB |
testcase_05 | AC | 83 ms
39,020 KB |
testcase_06 | AC | 75 ms
38,616 KB |
testcase_07 | AC | 70 ms
38,364 KB |
testcase_08 | AC | 267 ms
52,232 KB |
testcase_09 | AC | 253 ms
52,168 KB |
testcase_10 | AC | 66 ms
37,608 KB |
testcase_11 | AC | 70 ms
37,876 KB |
testcase_12 | AC | 70 ms
38,072 KB |
testcase_13 | AC | 241 ms
52,136 KB |
testcase_14 | AC | 255 ms
52,304 KB |
testcase_15 | AC | 204 ms
51,924 KB |
testcase_16 | AC | 283 ms
52,188 KB |
testcase_17 | AC | 291 ms
52,316 KB |
testcase_18 | AC | 145 ms
46,604 KB |
testcase_19 | AC | 220 ms
49,132 KB |
testcase_20 | AC | 370 ms
52,328 KB |
testcase_21 | AC | 418 ms
52,084 KB |
testcase_22 | AC | 411 ms
52,092 KB |
testcase_23 | AC | 393 ms
52,096 KB |
testcase_24 | AC | 213 ms
52,036 KB |
testcase_25 | AC | 215 ms
52,256 KB |
testcase_26 | AC | 283 ms
52,120 KB |
testcase_27 | AC | 276 ms
52,064 KB |
testcase_28 | AC | 287 ms
51,956 KB |
testcase_29 | AC | 280 ms
52,168 KB |
testcase_30 | AC | 68 ms
38,304 KB |
testcase_31 | AC | 71 ms
38,324 KB |
testcase_32 | AC | 77 ms
38,396 KB |
testcase_33 | AC | 72 ms
37,924 KB |
testcase_34 | AC | 83 ms
38,496 KB |
testcase_35 | AC | 69 ms
37,976 KB |
testcase_36 | AC | 76 ms
38,576 KB |
testcase_37 | AC | 76 ms
38,464 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { private static int[] dy = {0,1,0,-1}; private static int[] dx = {1,0,-1,0}; private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws Exception { int[] h_w = readIntArray(); int h = h_w[0]; int w = h_w[1]; int[] aInfo = readIntArray(); int a = aInfo[0]; int si = aInfo[1]; int sj = aInfo[2]; int[] bInfo = readIntArray(); int b = bInfo[0]; int gi = bInfo[1]; int gj = bInfo[2]; boolean[][] field = new boolean[h][w]; for(int i = 0 ; i < h ; i++){ char[] terrains = br.readLine().toCharArray(); for(int j = 0 ; j < w ; j++){ if(terrains[j] == '*'){ field[i][j] = true; } } } boolean[][][] exist = new boolean[2000][h+1][w+1]; exist[a][si][sj] = true; String judge = bfs(field , a , si , sj , b , gi , gj , h , w , exist); System.out.println(judge); } private static String bfs(boolean[][] field , int firstVolume , int firstH , int firstW , int goalVolume , int goalH , int goalW , int h , int w , boolean[][][] exist){ ArrayDeque<Pair> todo = new ArrayDeque<>(); todo.addLast(new Pair(firstVolume , firstH , firstW)); while(!todo.isEmpty()){ Pair p = todo.pollFirst(); int currentH = p.getY(); int currentW = p.getX(); for(int i = 0 ; i < 4 ; i++){ int nextH = currentH + dy[i]; int nextW = currentW + dx[i]; if(nextH < 0 || nextH >= h || nextW < 0 || nextW >= w){ continue; } int size = p.getSize(); if(field[nextH][nextW]){ size++; }else{ size--; } if(size >= 2000 || size <= 0){ continue; } if(exist[size][nextH][nextW]){ continue; } //System.out.println(size+":"+nextH+":"+nextW); exist[size][nextH][nextW] = true; todo.addLast(new Pair(size , nextH , nextW)); } } return exist[goalVolume][goalH][goalW] ? "Yes" : "No"; } private static int[] readIntArray() throws Exception{ int[] intArray = Arrays.stream(br.readLine().split(" ")) .mapToInt(Integer::parseInt).toArray(); return intArray; } } class Pair{ int size , y , x; public Pair(int size , int y , int x){ this.size = size; this.y = y; this.x = x; } public int getSize(){ return size; } public int getY(){ return y; } public int getX(){ return x; } }