結果
問題 | No.157 2つの空洞 |
ユーザー | yoza |
提出日時 | 2015-02-27 02:31:23 |
言語 | Nim (2.0.2) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,896 bytes |
コンパイル時間 | 3,848 ms |
コンパイル使用メモリ | 66,176 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-06-28 22:24:13 |
合計ジャッジ時間 | 7,198 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
7,936 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | TLE | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
コンパイルメッセージ
/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]
ソースコード
import strutils, sequtils, algorithm, mathvarwh = split(readLine(stdin), ' ').map(parseInt)count = 0board = newSeq[seq[int]](wh[1])dire = [[0, -1], [1, 0], [0, 1], [-1, 0]]pre = 0proc bfs(x, y, count: int): int =var min_dis = high(int)if count == 0:for i in countup(1, wh[1] - 2):for j in countup(1, wh[0] - 2):if board[i][j] == 1:for d in dire:if 0 < j + d[0] and j + d[0] < wh[0] - 1 and 0 < i + d[1] and i + d[1] < wh[1] - 1:if board[i+d[1]][j+d[0]] == -1:min_dis = min(bfs(j + d[0], i + d[1], count + 1), min_dis)return min_diselse:board[y][x] = -2for 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:if board[y+d[1]][x+d[0]] == 2:board[y][x] = -1return countfor 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:if board[y+d[1]][x+d[0]] == -1:min_dis = min(bfs(x + d[0], y + d[1], count + 1), min_dis)board[y][x] = -1return min_disproc 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 += 1board[i][j] = prefor d in dire:init(pre, j + d[0], i + d[1])else:if board[y][x] == 0:board[y][x] = prefor 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: 0return)init(pre, 1, 1)echo(bfs(0, 0, 0))