結果
問題 | No.323 yuki国 |
ユーザー | Grenache |
提出日時 | 2016-05-27 19:35:22 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 699 ms / 5,000 ms |
コード長 | 3,280 bytes |
コンパイル時間 | 4,403 ms |
コンパイル使用メモリ | 76,232 KB |
実行使用メモリ | 69,276 KB |
最終ジャッジ日時 | 2023-09-10 21:29:30 |
合計ジャッジ時間 | 12,784 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
49,340 KB |
testcase_01 | AC | 44 ms
49,352 KB |
testcase_02 | AC | 44 ms
49,320 KB |
testcase_03 | AC | 54 ms
50,420 KB |
testcase_04 | AC | 45 ms
49,216 KB |
testcase_05 | AC | 44 ms
49,632 KB |
testcase_06 | AC | 44 ms
49,348 KB |
testcase_07 | AC | 45 ms
49,268 KB |
testcase_08 | AC | 46 ms
49,236 KB |
testcase_09 | AC | 512 ms
68,944 KB |
testcase_10 | AC | 44 ms
49,316 KB |
testcase_11 | AC | 48 ms
49,524 KB |
testcase_12 | AC | 48 ms
49,308 KB |
testcase_13 | AC | 541 ms
68,956 KB |
testcase_14 | AC | 46 ms
49,180 KB |
testcase_15 | AC | 290 ms
69,000 KB |
testcase_16 | AC | 518 ms
69,124 KB |
testcase_17 | AC | 556 ms
68,608 KB |
testcase_18 | AC | 210 ms
57,100 KB |
testcase_19 | AC | 49 ms
49,324 KB |
testcase_20 | AC | 617 ms
63,676 KB |
testcase_21 | AC | 49 ms
49,672 KB |
testcase_22 | AC | 699 ms
64,120 KB |
testcase_23 | AC | 50 ms
49,396 KB |
testcase_24 | AC | 314 ms
69,192 KB |
testcase_25 | AC | 46 ms
49,204 KB |
testcase_26 | AC | 475 ms
61,760 KB |
testcase_27 | AC | 45 ms
49,312 KB |
testcase_28 | AC | 563 ms
69,024 KB |
testcase_29 | AC | 543 ms
69,276 KB |
testcase_30 | AC | 44 ms
49,208 KB |
testcase_31 | AC | 45 ms
49,504 KB |
testcase_32 | AC | 51 ms
47,696 KB |
testcase_33 | AC | 45 ms
49,240 KB |
testcase_34 | AC | 45 ms
49,832 KB |
testcase_35 | AC | 45 ms
49,508 KB |
testcase_36 | AC | 44 ms
49,256 KB |
testcase_37 | AC | 45 ms
49,388 KB |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.Arrays; import java.util.Deque; import java.util.Iterator; public class Main_yukicoder323_1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int h = sc.nextInt(); int w = sc.nextInt(); int a = sc.nextInt(); int si = sc.nextInt(); int sj = sc.nextInt(); int b = sc.nextInt(); int gi = sc.nextInt(); int gj = sc.nextInt(); char[][] akichi = new char[h][]; for (int i = 0; i < h; i++) { akichi[i] = sc.next().toCharArray(); } if (Math.abs(a - b) % 2 != Math.abs(si - gi + sj - gj) % 2) { pr.println("No"); sc.close(); pr.close(); return; } int[] di = {-1, 0, 1, 0}; int[] dj = {0, 1, 0, -1}; int max = Math.max(a, b) + h * w; boolean[][][] used = new boolean[h][w][max + 1]; Deque<Integer> qi = new ArrayDeque<Integer>(); Deque<Integer> qj = new ArrayDeque<Integer>(); Deque<Integer> qs = new ArrayDeque<Integer>(); qi.add(si); qj.add(sj); qs.add(a); used[si][sj][a] = true; while (!qi.isEmpty()) { int i = qi.remove(); int j = qj.remove(); int size = qs.remove(); for (int k = 0; k < di.length; k++) { int ni = i + di[k]; int nj = j + dj[k]; if (ni < 0 || ni >= h || nj < 0 || nj >= w) { continue; } int nyuki; if (akichi[ni][nj] == '*') { nyuki = size + 1; } else { nyuki = size - 1; } if (nyuki == 0) { continue; } if (nyuki > max || used[ni][nj][nyuki]) { continue; } used[ni][nj][nyuki] = true; qi.add(ni); qj.add(nj); qs.add(nyuki); } } if (used[gi][gj][b]) { pr.println("Yes"); } else { pr.println("No"); } pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }