結果

問題 No.5006 Hidden Maze
ユーザー ks2mks2m
提出日時 2022-06-12 17:12:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,049 ms / 2,000 ms
コード長 4,002 bytes
コンパイル時間 2,760 ms
実行使用メモリ 71,064 KB
スコア 83,912
平均クエリ数 161.88
最終ジャッジ日時 2022-06-12 17:13:17
合計ジャッジ時間 12,656 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 175 ms
56,092 KB
testcase_01 AC 175 ms
56,732 KB
testcase_02 AC 139 ms
54,404 KB
testcase_03 AC 158 ms
53,904 KB
testcase_04 AC 155 ms
54,060 KB
testcase_05 AC 267 ms
60,824 KB
testcase_06 AC 336 ms
63,296 KB
testcase_07 AC 791 ms
71,064 KB
testcase_08 AC 476 ms
66,852 KB
testcase_09 AC 108 ms
51,864 KB
testcase_10 AC 162 ms
55,896 KB
testcase_11 AC 179 ms
57,116 KB
testcase_12 AC 216 ms
57,636 KB
testcase_13 AC 224 ms
58,120 KB
testcase_14 AC 197 ms
57,688 KB
testcase_15 AC 124 ms
53,216 KB
testcase_16 AC 154 ms
54,756 KB
testcase_17 AC 160 ms
55,024 KB
testcase_18 AC 202 ms
57,940 KB
testcase_19 AC 141 ms
53,352 KB
testcase_20 AC 173 ms
56,580 KB
testcase_21 AC 227 ms
58,428 KB
testcase_22 AC 168 ms
56,044 KB
testcase_23 AC 176 ms
56,016 KB
testcase_24 AC 573 ms
65,628 KB
testcase_25 AC 180 ms
57,096 KB
testcase_26 AC 672 ms
67,380 KB
testcase_27 AC 187 ms
58,396 KB
testcase_28 AC 157 ms
54,128 KB
testcase_29 AC 164 ms
55,308 KB
testcase_30 AC 158 ms
53,668 KB
testcase_31 AC 157 ms
53,980 KB
testcase_32 AC 267 ms
59,060 KB
testcase_33 AC 204 ms
57,916 KB
testcase_34 AC 198 ms
57,724 KB
testcase_35 AC 193 ms
56,856 KB
testcase_36 AC 143 ms
53,116 KB
testcase_37 AC 147 ms
54,932 KB
testcase_38 AC 422 ms
66,580 KB
testcase_39 AC 601 ms
67,952 KB
testcase_40 AC 166 ms
55,324 KB
testcase_41 AC 174 ms
56,564 KB
testcase_42 AC 344 ms
62,900 KB
testcase_43 AC 201 ms
57,700 KB
testcase_44 AC 188 ms
55,584 KB
testcase_45 AC 393 ms
65,996 KB
testcase_46 AC 532 ms
65,880 KB
testcase_47 AC 172 ms
55,336 KB
testcase_48 AC 324 ms
65,072 KB
testcase_49 AC 938 ms
70,204 KB
testcase_50 AC 217 ms
58,172 KB
testcase_51 AC 167 ms
54,624 KB
testcase_52 AC 155 ms
53,576 KB
testcase_53 AC 298 ms
60,384 KB
testcase_54 AC 192 ms
57,276 KB
testcase_55 AC 244 ms
59,844 KB
testcase_56 AC 169 ms
55,724 KB
testcase_57 AC 889 ms
70,172 KB
testcase_58 AC 160 ms
55,192 KB
testcase_59 AC 249 ms
59,652 KB
testcase_60 AC 207 ms
57,820 KB
testcase_61 AC 178 ms
55,492 KB
testcase_62 AC 289 ms
63,372 KB
testcase_63 AC 181 ms
57,808 KB
testcase_64 AC 218 ms
58,988 KB
testcase_65 AC 149 ms
54,240 KB
testcase_66 AC 161 ms
53,644 KB
testcase_67 AC 130 ms
52,484 KB
testcase_68 AC 263 ms
59,588 KB
testcase_69 AC 269 ms
59,584 KB
testcase_70 AC 146 ms
53,972 KB
testcase_71 AC 234 ms
57,880 KB
testcase_72 AC 136 ms
50,204 KB
testcase_73 AC 465 ms
68,252 KB
testcase_74 AC 411 ms
65,520 KB
testcase_75 AC 238 ms
58,592 KB
testcase_76 AC 145 ms
53,444 KB
testcase_77 AC 483 ms
65,272 KB
testcase_78 AC 220 ms
58,692 KB
testcase_79 AC 906 ms
69,456 KB
testcase_80 AC 140 ms
54,212 KB
testcase_81 AC 165 ms
54,792 KB
testcase_82 AC 191 ms
56,408 KB
testcase_83 AC 175 ms
55,320 KB
testcase_84 AC 156 ms
54,324 KB
testcase_85 AC 371 ms
65,296 KB
testcase_86 AC 133 ms
52,816 KB
testcase_87 AC 194 ms
56,992 KB
testcase_88 AC 250 ms
59,156 KB
testcase_89 AC 316 ms
63,120 KB
testcase_90 AC 189 ms
56,464 KB
testcase_91 AC 168 ms
54,420 KB
testcase_92 AC 242 ms
59,440 KB
testcase_93 AC 139 ms
53,624 KB
testcase_94 AC 152 ms
55,000 KB
testcase_95 AC 177 ms
55,944 KB
testcase_96 AC 188 ms
54,612 KB
testcase_97 AC 383 ms
65,172 KB
testcase_98 AC 1,049 ms
70,404 KB
testcase_99 AC 288 ms
63,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 hw = h + w;
		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.15 + 0.8 * q / 100;
		List<Integer> list = new ArrayList<>(4);
		for (int i = 0; i < 4; i++) {
			list.add(i);
		}
		int z = 0;
		double rate = 0;

		while (true) {
			// TODO 調整
			if (z < hw * 0.9) {
				rate = -1;
			} else if (z < hw * 1.3) {
				rate = 0;
			} else {
				rate = 2;
			}
			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 * rate;
					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.02;
				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') {
					if (yoko[cx][cy] > 0) {
						z++;
						yoko[cx][cy] = 0;
					}
					cx++;
				} else if (c == 'R') {
					if (tate[cx][cy] > 0) {
						z++;
						tate[cx][cy] = 0;
					}
					cy++;
				} else if (c == 'U') {
					cx--;
					if (yoko[cx][cy] > 0) {
						z++;
						yoko[cx][cy] = 0;
					}
				} else if (c == 'L') {
					cy--;
					if (tate[cx][cy] > 0) {
						z++;
						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);
		}
	}
}
0