結果

問題 No.157 2つの空洞
ユーザー むらためむらため
提出日時 2019-01-19 07:49:06
言語 Nim
(2.0.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 2,980 ms
コンパイル使用メモリ 70,948 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 02:15:44
合計ジャッジ時間 3,941 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import sequtils

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

let w = scan() # 20
let h = scan() # 20
let C = newSeqWith(h,toSeq(stdin.readLine().items))
# 2つ
const dxdy4 :seq[tuple[x,y:int]] = @[(0,1),(1,0),(0,-1),(-1,0)]
var A = newSeqWith(h,newSeqWith(w,-1))
proc embA()=
  proc toA(x,y:int) =
    if A[y][x] != -1 or C[y][x] != '.': return
    A[y][x] = 0
    for d in dxdy4: toA(x+d.x,y+d.y)
  for y in 1..h-1:
    for x in 1..w-1:
      if C[y][x] == '.':
        toA(x,y)
        return
embA()

for lv in 0..<400:
  for y in 1..<h-1:
    for x in 1..<w-1:
      let a = A[y][x]
      if lv != a : continue
      for d in dxdy4:
        let y1 = y+d.y
        let x1 = x+d.x
        if A[y1][x1] != -1 : continue
        A[y1][x1] = lv + 1
        for d2 in dxdy4:
          let x2 = x + d.x + d2.x
          let y2 = y + d.y + d2.y
          if x2 < 0 or y2 < 0 or x2 >= w or y2 >= h : continue
          if C[y2][x2] == '.' and A[y2][x2] == -1:
            echo lv + 1
            quit 0
0