結果
問題 | No.5006 Hidden Maze |
ユーザー | ks2m |
提出日時 | 2022-06-12 15:43:23 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 624 ms / 2,000 ms |
コード長 | 3,185 bytes |
コンパイル時間 | 2,638 ms |
実行使用メモリ | 69,240 KB |
スコア | 75,648 |
平均クエリ数 | 244.52 |
最終ジャッジ日時 | 2022-06-12 15:44:05 |
合計ジャッジ時間 | 28,396 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge16 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 181 ms
58,472 KB |
testcase_01 | AC | 258 ms
60,036 KB |
testcase_02 | AC | 220 ms
57,536 KB |
testcase_03 | AC | 126 ms
53,108 KB |
testcase_04 | AC | 163 ms
55,188 KB |
testcase_05 | AC | 194 ms
58,600 KB |
testcase_06 | AC | 224 ms
59,632 KB |
testcase_07 | AC | 255 ms
59,924 KB |
testcase_08 | AC | 163 ms
67,492 KB |
testcase_09 | AC | 176 ms
57,628 KB |
testcase_10 | AC | 169 ms
56,160 KB |
testcase_11 | AC | 146 ms
59,672 KB |
testcase_12 | AC | 172 ms
57,164 KB |
testcase_13 | AC | 157 ms
53,492 KB |
testcase_14 | AC | 168 ms
65,012 KB |
testcase_15 | AC | 163 ms
55,120 KB |
testcase_16 | AC | 132 ms
54,652 KB |
testcase_17 | AC | 114 ms
51,460 KB |
testcase_18 | AC | 239 ms
59,836 KB |
testcase_19 | AC | 155 ms
54,172 KB |
testcase_20 | AC | 158 ms
57,132 KB |
testcase_21 | AC | 139 ms
60,192 KB |
testcase_22 | AC | 169 ms
57,880 KB |
testcase_23 | AC | 203 ms
59,300 KB |
testcase_24 | AC | 241 ms
63,784 KB |
testcase_25 | AC | 121 ms
51,940 KB |
testcase_26 | AC | 453 ms
65,736 KB |
testcase_27 | AC | 85 ms
56,964 KB |
testcase_28 | AC | 103 ms
51,112 KB |
testcase_29 | AC | 114 ms
51,516 KB |
testcase_30 | AC | 137 ms
52,724 KB |
testcase_31 | AC | 118 ms
53,836 KB |
testcase_32 | AC | 197 ms
57,740 KB |
testcase_33 | AC | 167 ms
57,504 KB |
testcase_34 | AC | 143 ms
53,532 KB |
testcase_35 | AC | 147 ms
56,240 KB |
testcase_36 | AC | 97 ms
54,092 KB |
testcase_37 | AC | 460 ms
66,816 KB |
testcase_38 | AC | 203 ms
63,032 KB |
testcase_39 | AC | 122 ms
52,404 KB |
testcase_40 | AC | 158 ms
54,312 KB |
testcase_41 | AC | 195 ms
60,052 KB |
testcase_42 | AC | 152 ms
58,708 KB |
testcase_43 | AC | 161 ms
57,504 KB |
testcase_44 | AC | 141 ms
53,484 KB |
testcase_45 | AC | 195 ms
67,320 KB |
testcase_46 | AC | 624 ms
69,240 KB |
testcase_47 | AC | 148 ms
53,856 KB |
testcase_48 | AC | 179 ms
59,636 KB |
testcase_49 | AC | 460 ms
65,436 KB |
testcase_50 | AC | 195 ms
58,580 KB |
testcase_51 | AC | 184 ms
55,808 KB |
testcase_52 | AC | 203 ms
57,388 KB |
testcase_53 | AC | 213 ms
59,500 KB |
testcase_54 | AC | 80 ms
54,220 KB |
testcase_55 | AC | 177 ms
57,088 KB |
testcase_56 | AC | 152 ms
54,340 KB |
testcase_57 | AC | 286 ms
60,400 KB |
testcase_58 | AC | 181 ms
56,248 KB |
testcase_59 | AC | 116 ms
53,900 KB |
testcase_60 | AC | 140 ms
53,600 KB |
testcase_61 | AC | 146 ms
54,100 KB |
testcase_62 | AC | 163 ms
54,688 KB |
testcase_63 | AC | 131 ms
52,540 KB |
testcase_64 | AC | 174 ms
57,104 KB |
testcase_65 | AC | 91 ms
56,780 KB |
testcase_66 | AC | 146 ms
53,484 KB |
testcase_67 | AC | 172 ms
56,768 KB |
testcase_68 | AC | 301 ms
63,100 KB |
testcase_69 | AC | 150 ms
54,224 KB |
testcase_70 | AC | 108 ms
50,496 KB |
testcase_71 | AC | 167 ms
53,224 KB |
testcase_72 | AC | 93 ms
54,136 KB |
testcase_73 | AC | 213 ms
60,296 KB |
testcase_74 | AC | 142 ms
52,964 KB |
testcase_75 | AC | 477 ms
65,868 KB |
testcase_76 | AC | 135 ms
52,364 KB |
testcase_77 | AC | 260 ms
59,808 KB |
testcase_78 | AC | 160 ms
54,948 KB |
testcase_79 | AC | 326 ms
64,544 KB |
testcase_80 | AC | 208 ms
57,852 KB |
testcase_81 | AC | 129 ms
60,684 KB |
testcase_82 | AC | 190 ms
57,060 KB |
testcase_83 | AC | 113 ms
52,152 KB |
testcase_84 | AC | 159 ms
59,976 KB |
testcase_85 | AC | 219 ms
64,584 KB |
testcase_86 | AC | 98 ms
51,584 KB |
testcase_87 | AC | 212 ms
64,936 KB |
testcase_88 | AC | 184 ms
58,048 KB |
testcase_89 | AC | 248 ms
68,788 KB |
testcase_90 | AC | 169 ms
55,692 KB |
testcase_91 | AC | 172 ms
58,276 KB |
testcase_92 | AC | 212 ms
58,272 KB |
testcase_93 | AC | 144 ms
54,572 KB |
testcase_94 | AC | 324 ms
65,036 KB |
testcase_95 | AC | 215 ms
59,072 KB |
testcase_96 | AC | 132 ms
52,908 KB |
testcase_97 | AC | 426 ms
64,484 KB |
testcase_98 | AC | 281 ms
65,092 KB |
testcase_99 | AC | 135 ms
54,824 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]; double border = 0; List<Integer> list = new ArrayList<>(4); for (int i = 0; i < 4; i++) { list.add(i); } while (true) { border = Math.min(border, 0.995); // 探索 int[][] d = new int[h][w]; int[][] pre = new int[h][w]; for (int i = 0; i < h; i++) { Arrays.fill(d[i], -1); Arrays.fill(pre[i], -1); } d[0][0] = 0; Queue<Integer> que = new ArrayDeque<>(); que.add(0); while (!que.isEmpty()) { int cur = que.poll(); int cx = cur / w; int cy = cur % 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 || i == 0 && yoko[cx][cy] > border || i == 1 && tate[cx][cy] > border || i == 2 && yoko[nx][ny] > border || i == 3 && tate[nx][ny] > border) { continue; } if (d[nx][ny] == -1) { que.add(nx * w + ny); d[nx][ny] = d[cx][cy] + 1; pre[nx][ny] = cur; } } } if (pre[h1][w1] == -1) { border += 0.001; 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] = -1; cx++; } else if (c == 'R') { tate[cx][cy] = -1; cy++; } else if (c == 'U') { cx--; yoko[cx][cy] = -1; } else if (c == 'L') { cy--; tate[cx][cy] = -1; } } 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; } border += 0.002; } } }