結果

問題 No.2657 Falling Block Game
ユーザー ks2mks2m
提出日時 2024-03-01 22:37:59
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,044 bytes
コンパイル時間 2,813 ms
コンパイル使用メモリ 81,116 KB
実行使用メモリ 76,528 KB
最終ジャッジ日時 2024-03-01 22:38:08
合計ジャッジ時間 8,031 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
64,908 KB
testcase_01 AC 135 ms
57,832 KB
testcase_02 AC 134 ms
56,292 KB
testcase_03 AC 134 ms
57,804 KB
testcase_04 AC 477 ms
70,032 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] s = new char[h][w];
		for (int i = 0; i < h; i++) {
			s[i] = sc.next().toCharArray();
		}
		sc.close();

		int inf = 100000000;
		int[][] d = new int[h][w];
		for (int i = 0; i < h; i++) {
			Arrays.fill(d[i], inf);
		}

		PriorityQueue<Obj> que = new PriorityQueue<>((o1, o2) -> o1.d - o2.d);
		int h1 = h - 1;
		for (int j = 0; j < w; j++) {
			if (s[h1][j] == '.') {
				d[h1][j] = 0;
				que.add(new Obj(h1, j, d[h1][j]));
			}
		}

		while (!que.isEmpty()) {
			Obj o = que.poll();
			if (d[o.i][o.j] < o.d) {
				continue;
			}
			if (o.i > 0) {
				int ni = o.i - 1;
				int end = Math.min(o.j + o.d, w - 1);
				for (int nj = o.j; nj <= end; nj++) {
					if (s[ni][nj] == '#') {
						break;
					}
					int alt = o.d;
					if (d[ni][nj] > alt) {
						d[ni][nj] = alt;
						que.add(new Obj(ni, nj, alt));
					}
				}

				end = Math.max(o.j - o.d, 0);
				for (int nj = o.j; nj >= end; nj--) {
					if (s[ni][nj] == '#') {
						break;
					}
					int alt = o.d;
					if (d[ni][nj] > alt) {
						d[ni][nj] = alt;
						que.add(new Obj(ni, nj, alt));
					}
				}
			}
			int ni = o.i;
			if (o.j > 0) {
				int nj = o.j - 1;
				if (s[ni][nj] == '.') {
					int alt = o.d + 1;
					if (d[ni][nj] > alt) {
						d[ni][nj] = alt;
						que.add(new Obj(ni, nj, alt));
					}
				}
			}
			if (o.j < w - 1) {
				int nj = o.j + 1;
				if (s[ni][nj] == '.') {
					int alt = o.d + 1;
					if (d[ni][nj] > alt) {
						d[ni][nj] = alt;
						que.add(new Obj(ni, nj, alt));
					}
				}
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int j = 0; j < w; j++) {
			pw.println(d[0][j]);
		}
		pw.flush();
	}

	static class Obj {
		int i, j, d;

		public Obj(int i, int j, int d) {
			this.i = i;
			this.j = j;
			this.d = d;
		}
	}
}
0