結果
問題 | No.5006 Hidden Maze |
ユーザー | ks2m |
提出日時 | 2022-06-12 17:39:42 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,512 ms / 2,000 ms |
コード長 | 3,628 bytes |
コンパイル時間 | 2,186 ms |
実行使用メモリ | 84,120 KB |
スコア | 84,817 |
平均クエリ数 | 152.83 |
最終ジャッジ日時 | 2022-06-12 17:40:30 |
合計ジャッジ時間 | 14,848 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 144 ms
58,416 KB |
testcase_01 | AC | 994 ms
71,796 KB |
testcase_02 | AC | 148 ms
59,128 KB |
testcase_03 | AC | 199 ms
57,188 KB |
testcase_04 | AC | 179 ms
59,088 KB |
testcase_05 | AC | 355 ms
63,872 KB |
testcase_06 | AC | 181 ms
58,536 KB |
testcase_07 | AC | 221 ms
58,200 KB |
testcase_08 | AC | 350 ms
66,628 KB |
testcase_09 | AC | 133 ms
57,244 KB |
testcase_10 | AC | 202 ms
63,948 KB |
testcase_11 | AC | 138 ms
52,752 KB |
testcase_12 | AC | 278 ms
61,824 KB |
testcase_13 | AC | 125 ms
58,076 KB |
testcase_14 | AC | 296 ms
61,420 KB |
testcase_15 | AC | 202 ms
64,532 KB |
testcase_16 | AC | 188 ms
63,012 KB |
testcase_17 | AC | 136 ms
53,192 KB |
testcase_18 | AC | 501 ms
67,328 KB |
testcase_19 | AC | 228 ms
58,480 KB |
testcase_20 | AC | 166 ms
61,352 KB |
testcase_21 | AC | 226 ms
70,452 KB |
testcase_22 | AC | 151 ms
66,692 KB |
testcase_23 | AC | 383 ms
77,180 KB |
testcase_24 | AC | 347 ms
75,212 KB |
testcase_25 | AC | 216 ms
69,664 KB |
testcase_26 | AC | 1,394 ms
83,032 KB |
testcase_27 | AC | 205 ms
69,168 KB |
testcase_28 | AC | 150 ms
67,136 KB |
testcase_29 | AC | 219 ms
69,764 KB |
testcase_30 | AC | 194 ms
70,220 KB |
testcase_31 | AC | 137 ms
63,708 KB |
testcase_32 | AC | 306 ms
74,084 KB |
testcase_33 | AC | 268 ms
72,764 KB |
testcase_34 | AC | 183 ms
68,636 KB |
testcase_35 | AC | 239 ms
70,576 KB |
testcase_36 | AC | 117 ms
63,452 KB |
testcase_37 | AC | 1,400 ms
80,036 KB |
testcase_38 | AC | 341 ms
75,012 KB |
testcase_39 | AC | 436 ms
76,936 KB |
testcase_40 | AC | 169 ms
67,696 KB |
testcase_41 | AC | 267 ms
71,904 KB |
testcase_42 | AC | 237 ms
70,804 KB |
testcase_43 | AC | 298 ms
72,116 KB |
testcase_44 | AC | 219 ms
70,464 KB |
testcase_45 | AC | 301 ms
72,108 KB |
testcase_46 | AC | 1,506 ms
84,092 KB |
testcase_47 | AC | 145 ms
67,996 KB |
testcase_48 | AC | 655 ms
79,552 KB |
testcase_49 | AC | 1,427 ms
82,256 KB |
testcase_50 | AC | 166 ms
68,352 KB |
testcase_51 | AC | 403 ms
78,404 KB |
testcase_52 | AC | 191 ms
69,448 KB |
testcase_53 | AC | 217 ms
70,164 KB |
testcase_54 | AC | 635 ms
79,772 KB |
testcase_55 | AC | 558 ms
79,592 KB |
testcase_56 | AC | 278 ms
72,764 KB |
testcase_57 | AC | 394 ms
76,664 KB |
testcase_58 | AC | 212 ms
69,924 KB |
testcase_59 | AC | 152 ms
67,352 KB |
testcase_60 | AC | 197 ms
69,736 KB |
testcase_61 | AC | 262 ms
71,996 KB |
testcase_62 | AC | 450 ms
76,512 KB |
testcase_63 | AC | 367 ms
78,612 KB |
testcase_64 | AC | 332 ms
76,744 KB |
testcase_65 | AC | 930 ms
79,548 KB |
testcase_66 | AC | 147 ms
66,952 KB |
testcase_67 | AC | 134 ms
64,680 KB |
testcase_68 | AC | 258 ms
71,876 KB |
testcase_69 | AC | 240 ms
70,552 KB |
testcase_70 | AC | 253 ms
70,300 KB |
testcase_71 | AC | 169 ms
67,344 KB |
testcase_72 | AC | 150 ms
67,016 KB |
testcase_73 | AC | 397 ms
76,096 KB |
testcase_74 | AC | 447 ms
77,160 KB |
testcase_75 | AC | 998 ms
79,956 KB |
testcase_76 | AC | 182 ms
69,036 KB |
testcase_77 | AC | 1,431 ms
84,120 KB |
testcase_78 | AC | 179 ms
67,944 KB |
testcase_79 | AC | 1,341 ms
83,676 KB |
testcase_80 | AC | 149 ms
67,388 KB |
testcase_81 | AC | 348 ms
75,536 KB |
testcase_82 | AC | 200 ms
69,320 KB |
testcase_83 | AC | 170 ms
67,912 KB |
testcase_84 | AC | 180 ms
68,584 KB |
testcase_85 | AC | 176 ms
68,932 KB |
testcase_86 | AC | 114 ms
63,112 KB |
testcase_87 | AC | 245 ms
70,804 KB |
testcase_88 | AC | 403 ms
76,772 KB |
testcase_89 | AC | 1,171 ms
82,728 KB |
testcase_90 | AC | 181 ms
68,480 KB |
testcase_91 | AC | 212 ms
70,064 KB |
testcase_92 | AC | 351 ms
75,552 KB |
testcase_93 | AC | 218 ms
69,168 KB |
testcase_94 | AC | 1,512 ms
82,840 KB |
testcase_95 | AC | 643 ms
79,196 KB |
testcase_96 | AC | 160 ms
66,484 KB |
testcase_97 | AC | 651 ms
78,952 KB |
testcase_98 | AC | 1,493 ms
80,352 KB |
testcase_99 | AC | 215 ms
69,848 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 * 1.8; // 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.005; 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); } } }