結果

問題 No.157 2つの空洞
ユーザー yozayoza
提出日時 2015-02-27 03:07:24
言語 Nim
(2.0.2)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,388 bytes
コンパイル時間 3,254 ms
コンパイル使用メモリ 71,920 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 07:53:53
合計ジャッジ時間 4,401 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 39) Warning: imported and not used: 'math' [UnusedImport]
/home/judge/data/code/Main.nim(1, 28) Warning: imported and not used: 'algorithm' [UnusedImport]

ソースコード

diff #

import strutils, sequtils, algorithm, math

var
  wh = split(readLine(stdin), ' ').map(parseInt)
  count = 0
  board = newSeq[seq[int]](wh[1])
  cave_points1 = newSeq[seq[int]](0)
  cave_points2 = newSeq[seq[int]](0)
  dire = [[0, -1], [1, 0], [0, 1], [-1, 0]]
  pre = 0
  min_v = high(int)

proc init(pre: var int; x, y: int) =
  if pre == 0:
    for i in countup(1, wh[1] - 2):
      for j in countup(1, wh[0] - 2):
        if board[i][j] == 0:
          pre += 1
          board[i][j] = pre
          if pre == 1:
            cave_points1.add(@[i,j])
          else:
            cave_points2.add(@[i,j])
          for d in dire:
            init(pre, j + d[0], i + d[1])
  else:
    if board[y][x] == 0:
      board[y][x] = pre
      if pre == 1:
        cave_points1.add(@[y,x])
      else:
        cave_points2.add(@[y,x])
      for d in dire:
        if 0 < x + d[0] and x + d[0] < wh[0] - 1 and 0 < y + d[1] and y + d[1] < wh[1] - 1:
          init(pre, x + d[0], y + d[1])

for i in countup(0, wh[1] - 1):
  var line = readLine(stdin)
  var row = newSeq[char](0)
  for c in line:
    row.add(c)
  board[i] = row.map(proc (x: char): int =
                       result = if x == '#': -1 else: 0
                       return)

init(pre, 1, 1)

for po1 in cave_points1:
  for po2 in cave_points2:
    min_v = min(min_v, abs(po1[1] - po2[1]) + abs(po1[0] - po2[0]) - 1)

echo(min_v)
0