結果

問題 No.157 2つの空洞
ユーザー 👑 tatt61880tatt61880
提出日時 2021-03-21 11:43:55
言語 Kuin
(KuinC++ v.2021.9.17)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,381 bytes
コンパイル時間 2,658 ms
コンパイル使用メモリ 160,500 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 17:48:14
合計ジャッジ時間 3,797 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 3 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 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
	const ch: char :: 'a'
	var flag: bool :: true
	var ans: int :: w + h
	for y(0, h - 1)
		for x(0, w - 1)
			if(c[y][x] = '.')
				if(flag)
					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 flag :: false
				else
					for dy(-h + 1, 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] = ch)
								do ans :: [ans, dx.abs() + dy.abs() - 1].min()
							end if
						end for
					end for
				end if
			end if
		end for
	end for
	
	do cui@print("\{ans}\n")
end func
0