結果

問題 No.157 2つの空洞
ユーザー 👑 tatt61880tatt61880
提出日時 2021-03-21 11:35:55
言語 Kuin
(KuinC++ v.2021.9.17)
結果
WA  
実行時間 -
コード長 1,357 bytes
コンパイル時間 3,459 ms
コンパイル使用メモリ 161,224 KB
実行使用メモリ 5,232 KB
最終ジャッジ日時 2023-10-14 17:48:06
合計ジャッジ時間 4,388 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,348 KB
testcase_17 WA -
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

func main()
	var w: int :: cui@inputInt()
	var h: int :: cui@inputInt()
	var c: [][]char :: #[h][]char
	for i(0, h - 1)
		do c[i] :: cui@input()
	end for
	var ch: char :: 'a'
	for y(0, h - 1)
		for x(0, w - 1)
			if(c[y][x] = '.')
				var dx: []int :: [1, 0, -1, 0]
				var dy: []int :: [0, 1, 0, -1]
				var qu: queue<int> :: #queue<int>
				do qu.add(y * w + x)
				while loop(^qu <> 0)
					var pos: int :: qu.get()
					var cy: int :: pos / w
					var cx: int :: pos % w
					if(c[cy][cx] <> '.')
						skip loop
					end if
					do c[cy][cx] :: ch
					for i(0, 3)
						var nx: int :: cx + dx[i]
						if(nx < 0 | w <= nx)
							skip i
						end if
						var ny: int :: cy + dy[i]
						if(ny < 0 | h <= ny)
							skip i
						end if
						if(c[ny][nx] = '.')
							do qu.add(ny * w + nx)
						end if
					end for
				end while
				do ch :: 'b'
			end if
		end for
	end for
	
	var ans: int :: w + h
	for y(0, h - 1)
		for x(0, w - 1)
			if(c[y][x] = 'a')
				for dy(0, h - 1)
					var ny: int :: y + dy
					if(ny < 0 | h <= ny)
						skip dy
					end if
					for dx(-w + 1, w - 1)
						var nx: int :: x + dx
						if(nx < 0 | w <= nx)
							skip dx
						end if
						if(c[ny][nx] = 'b')
							do ans :: [ans, dx.abs() + dy.abs() - 1].min()
						end if
					end for
				end for
			end if
		end for
	end for
	do cui@print("\{ans}\n")
end func
0