結果

問題 No.424 立体迷路
ユーザー 👑 tatt61880tatt61880
提出日時 2021-04-10 19:40:37
言語 Kuin
(KuinC++ v.2021.9.17)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,309 bytes
コンパイル時間 2,433 ms
コンパイル使用メモリ 165,372 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-14 18:25:01
合計ジャッジ時間 3,828 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 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,348 KB
testcase_15 AC 2 ms
4,356 KB
testcase_16 AC 2 ms
4,356 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 2 ms
4,352 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

func main()
	var h: int :: cui@inputInt()
	var w: int :: cui@inputInt()
	var sy: int :: cui@inputInt() - 1
	var sx: int :: cui@inputInt() - 1
	var gy: int :: cui@inputInt() - 1
	var gx: int :: cui@inputInt() - 1
	var b: [][]int :: #[h, w]int
	for y(0, h - 1)
		var s: []char :: cui@input()
		for x(0, w - 1)
			do b[y][x] :: s[x] $ int - '0' $ int
		end for
	end for
	var ok: [][]bool :: #[h, w]bool
	do ok[sy][sx] :: true
	
	var q: queue<int> :: #queue<int>
	do q.add(sy * w + sx)
	while(^q <> 0)
		var pos: int :: q.get()
		var x0: int :: pos % w
		var y0: int :: pos / w
		var dx: []int :: [1, 0, -1, 0]
		var dy: []int :: [0, 1, 0, -1]
		for i(0, 3)
			var x: int :: x0 + dx[i]
			var y: int :: y0 + dy[i]
			if(x < 0 | w <= x | y < 0 | h <= y)
				skip i
			end if
			if((b[y0][x0] - b[y][x]).abs() <= 1 & !ok[y][x])
				do ok[y][x] :: true
				do q.add(y * w + x)
			end if
		end for
		for i(0, 3)
			var x: int :: x0 + 2 * dx[i]
			var y: int :: y0 + 2 * dy[i]
			var xm: int :: x0 + dx[i]
			var ym: int :: y0 + dy[i]
			if(x < 0 | w <= x | y < 0 | h <= y)
				skip i
			end if
			if(b[y0][x0] = b[y][x] & b[ym][xm] < b[y][x] & !ok[y][x])
				do ok[y][x] :: true
				do q.add(y * w + x)
			end if
		end for
	end while
	
	var ans: bool :: ok[gy][gx]
	do cui@print((ans ?("YES", "NO")) ~ "\n")
end func
0