結果
問題 | No.5006 Hidden Maze |
ユーザー | ks2m |
提出日時 | 2022-06-12 16:37:41 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,521 ms / 2,000 ms |
コード長 | 3,628 bytes |
コンパイル時間 | 2,240 ms |
実行使用メモリ | 70,864 KB |
スコア | 84,260 |
平均クエリ数 | 158.40 |
最終ジャッジ日時 | 2022-06-12 16:38:33 |
合計ジャッジ時間 | 42,423 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 218 ms
57,400 KB |
testcase_01 | AC | 378 ms
64,800 KB |
testcase_02 | AC | 188 ms
58,144 KB |
testcase_03 | AC | 200 ms
57,480 KB |
testcase_04 | AC | 148 ms
56,752 KB |
testcase_05 | AC | 302 ms
62,152 KB |
testcase_06 | AC | 204 ms
57,208 KB |
testcase_07 | AC | 173 ms
55,340 KB |
testcase_08 | AC | 345 ms
63,204 KB |
testcase_09 | AC | 166 ms
56,416 KB |
testcase_10 | AC | 200 ms
57,580 KB |
testcase_11 | AC | 146 ms
53,652 KB |
testcase_12 | AC | 255 ms
59,272 KB |
testcase_13 | AC | 143 ms
53,188 KB |
testcase_14 | AC | 276 ms
61,344 KB |
testcase_15 | AC | 137 ms
53,636 KB |
testcase_16 | AC | 168 ms
57,060 KB |
testcase_17 | AC | 127 ms
52,692 KB |
testcase_18 | AC | 381 ms
63,236 KB |
testcase_19 | AC | 152 ms
53,768 KB |
testcase_20 | AC | 293 ms
58,860 KB |
testcase_21 | AC | 200 ms
58,748 KB |
testcase_22 | AC | 120 ms
51,176 KB |
testcase_23 | AC | 210 ms
57,652 KB |
testcase_24 | AC | 198 ms
56,572 KB |
testcase_25 | AC | 141 ms
54,944 KB |
testcase_26 | AC | 1,364 ms
68,780 KB |
testcase_27 | AC | 202 ms
58,160 KB |
testcase_28 | AC | 139 ms
53,384 KB |
testcase_29 | AC | 945 ms
67,244 KB |
testcase_30 | AC | 123 ms
51,260 KB |
testcase_31 | AC | 172 ms
54,760 KB |
testcase_32 | AC | 451 ms
65,840 KB |
testcase_33 | AC | 167 ms
54,192 KB |
testcase_34 | AC | 175 ms
56,604 KB |
testcase_35 | AC | 256 ms
61,884 KB |
testcase_36 | AC | 127 ms
51,292 KB |
testcase_37 | AC | 539 ms
64,244 KB |
testcase_38 | AC | 415 ms
64,736 KB |
testcase_39 | AC | 131 ms
53,396 KB |
testcase_40 | AC | 186 ms
55,792 KB |
testcase_41 | AC | 208 ms
58,980 KB |
testcase_42 | AC | 109 ms
50,728 KB |
testcase_43 | AC | 208 ms
58,180 KB |
testcase_44 | AC | 166 ms
55,344 KB |
testcase_45 | AC | 418 ms
63,976 KB |
testcase_46 | AC | 1,521 ms
70,864 KB |
testcase_47 | AC | 131 ms
52,208 KB |
testcase_48 | AC | 141 ms
53,780 KB |
testcase_49 | AC | 973 ms
64,684 KB |
testcase_50 | AC | 157 ms
54,064 KB |
testcase_51 | AC | 826 ms
67,156 KB |
testcase_52 | AC | 446 ms
65,564 KB |
testcase_53 | AC | 554 ms
63,960 KB |
testcase_54 | AC | 154 ms
56,072 KB |
testcase_55 | AC | 255 ms
59,416 KB |
testcase_56 | AC | 187 ms
57,636 KB |
testcase_57 | AC | 469 ms
64,276 KB |
testcase_58 | AC | 156 ms
54,832 KB |
testcase_59 | AC | 160 ms
56,952 KB |
testcase_60 | AC | 166 ms
54,672 KB |
testcase_61 | AC | 198 ms
57,820 KB |
testcase_62 | AC | 280 ms
61,592 KB |
testcase_63 | AC | 215 ms
57,540 KB |
testcase_64 | AC | 397 ms
65,200 KB |
testcase_65 | AC | 137 ms
54,620 KB |
testcase_66 | AC | 110 ms
51,520 KB |
testcase_67 | AC | 193 ms
57,900 KB |
testcase_68 | AC | 242 ms
59,560 KB |
testcase_69 | AC | 170 ms
57,800 KB |
testcase_70 | AC | 120 ms
53,732 KB |
testcase_71 | AC | 179 ms
58,016 KB |
testcase_72 | AC | 159 ms
56,640 KB |
testcase_73 | AC | 236 ms
59,348 KB |
testcase_74 | AC | 193 ms
56,660 KB |
testcase_75 | AC | 364 ms
64,436 KB |
testcase_76 | AC | 159 ms
55,880 KB |
testcase_77 | AC | 156 ms
55,220 KB |
testcase_78 | AC | 153 ms
54,248 KB |
testcase_79 | AC | 1,147 ms
64,340 KB |
testcase_80 | AC | 199 ms
57,776 KB |
testcase_81 | AC | 219 ms
58,516 KB |
testcase_82 | AC | 193 ms
57,140 KB |
testcase_83 | AC | 124 ms
51,120 KB |
testcase_84 | AC | 211 ms
58,396 KB |
testcase_85 | AC | 679 ms
67,008 KB |
testcase_86 | AC | 131 ms
52,720 KB |
testcase_87 | AC | 267 ms
59,340 KB |
testcase_88 | AC | 323 ms
61,120 KB |
testcase_89 | AC | 672 ms
66,604 KB |
testcase_90 | AC | 145 ms
52,492 KB |
testcase_91 | AC | 143 ms
54,340 KB |
testcase_92 | AC | 181 ms
57,700 KB |
testcase_93 | AC | 167 ms
56,016 KB |
testcase_94 | AC | 461 ms
64,352 KB |
testcase_95 | AC | 621 ms
66,584 KB |
testcase_96 | AC | 145 ms
54,660 KB |
testcase_97 | AC | 278 ms
63,492 KB |
testcase_98 | AC | 713 ms
65,356 KB |
testcase_99 | AC | 182 ms
57,448 KB |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Queue; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int h = Integer.parseInt(sa[0]); int w = Integer.parseInt(sa[1]); int p = Integer.parseInt(sa[2]); int h1 = h - 1; int w1 = w - 1; int q = 100 - p; int[] dx = {1, 0, -1, 0}; int[] dy = {0, 1, 0, -1}; double[][] tate = new double[h][w]; double[][] yoko = new double[h][w]; for (int i = 0; i < h; i++) { Arrays.fill(tate[i], 0.15); Arrays.fill(yoko[i], 0.15); } double border = 0.98; List<Integer> list = new ArrayList<>(4); for (int i = 0; i < 4; i++) { list.add(i); } while (true) { border = Math.min(border, 0.995); // 探索 double[][] d = new double[h][w]; int[][] pre = new int[h][w]; for (int i = 0; i < h; i++) { Arrays.fill(d[i], 1e9); Arrays.fill(pre[i], -1); } d[0][0] = 0; Queue<Node> que = new ArrayDeque<>(); que.add(new Node(0, 0)); while (!que.isEmpty()) { Node cur = que.poll(); int cx = cur.v / w; int cy = cur.v % w; Collections.shuffle(list); for (int i : list) { int nx = cx + dx[i]; int ny = cy + dy[i]; if (nx < 0 || h <= nx || ny < 0 || w <= ny) { continue; } double wall = 0; if (i == 0) wall = yoko[cx][cy]; else if (i == 1) wall = tate[cx][cy]; else if (i == 2) wall = yoko[nx][ny]; else if (i == 3) wall = tate[nx][ny]; if (wall > border) { continue; } double alt = cur.d + 1 + wall * 0.5; // TODO 調整 if (alt < d[nx][ny]) { que.add(new Node(nx * w + ny, alt)); d[nx][ny] = alt; pre[nx][ny] = cur.v; } } } if (pre[h1][w1] == -1) { border += 0.002; continue; } // 出力 StringBuilder sb = new StringBuilder(); int pos = h1 * w + w1; while (pos != 0) { int cx = pos / w; int cy = pos % w; int np = pre[cx][cy]; int nx = np / w; int ny = np % w; if (nx < cx) sb.append('D'); else if (ny < cy) sb.append('R'); else if (nx > cx) sb.append('U'); else if (ny > cy) sb.append('L'); else throw new RuntimeException(); pos = np; } sb.reverse(); System.out.println(sb.toString()); // 入力 int a = Integer.parseInt(br.readLine()); if (a == -1) { return; } // 壁更新 int cx = 0; int cy = 0; for (int i = 0; i < a; i++) { char c = sb.charAt(i); if (c == 'D') { yoko[cx][cy] = 0; cx++; } else if (c == 'R') { tate[cx][cy] = 0; cy++; } else if (c == 'U') { cx--; yoko[cx][cy] = 0; } else if (c == 'L') { cy--; tate[cx][cy] = 0; } } char c = sb.charAt(a); if (c == 'D' && yoko[cx][cy] > 0.1) { yoko[cx][cy] += (1 - yoko[cx][cy]) * q / 100; } else if (c == 'R' && tate[cx][cy] > 0.1) { tate[cx][cy] += (1 - tate[cx][cy]) * q / 100; } else if (c == 'U' && yoko[cx - 1][cy] > 0.1) { yoko[cx - 1][cy] += (1 - yoko[cx - 1][cy]) * q / 100; } else if (c == 'L' && tate[cx][cy - 1] > 0.1) { tate[cx][cy - 1] += (1 - tate[cx][cy - 1]) * q / 100; } } } static class Node implements Comparable<Node> { int v; double d; public Node(int v, double d) { this.v = v; this.d = d; } public int compareTo(Node o) { return Double.compare(d, o.d); } } }