結果

問題 No.424 立体迷路
ユーザー むらためむらため
提出日時 2019-01-26 01:44:05
言語 Nim
(2.0.2)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,131 bytes
コンパイル時間 2,469 ms
コンパイル使用メモリ 67,288 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 02:53:27
合計ジャッジ時間 4,835 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import sequtils

proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': break
    result = 10 * result + k.ord - '0'.ord


let h = scan()
let w = scan()
let (sy,sx) = (scan()-1,scan()-1)
let (gy,gx) = (scan()-1,scan()-1)
var B = newSeqWith(w,newSeqWith(h,0))
for y in 0..<h:
  for x in 0..<w:
    B[x][y] = getchar_unlocked().ord - '0'.ord
  discard getchar_unlocked()

var checked = newSeqWith(w,newSeqWith(h,false))
proc check(x,y:int) =
  if checked[x][y] : return
  checked[x][y] = true
  const dxdy4 :seq[tuple[x,y:int]] = @[(0,1),(1,0),(0,-1),(-1,0)]
  for d in dxdy4:
    let nx = x + d.x
    let ny = y + d.y
    if nx < 0 or ny < 0 or nx >= w or ny >= h : continue
    if (B[nx][ny] - B[x][y]).abs > 1: continue
    check(nx,ny)
  for d in dxdy4:
    let nx = x + d.x * 2
    let ny = y + d.y * 2
    if nx < 0 or ny < 0 or nx >= w or ny >= h : continue
    if B[nx][ny] != B[x][y] : continue
    if B[x+d.x][y+d.y] >= B[x][y] : continue
    check(nx,ny)
check(sx,sy)
if checked[gx][gy] : echo "YES"
else: echo "NO"
0