Submission #4039089


Source Code Expand

from sequtils import map, mapIt
from strutils import split, parseInt, parseFloat

import macros
macro unpack*(input: seq; count: static[int]): untyped =
  result = quote do: ()
  when NimMinor <= 13:
    for i in 0..<count: result[0].add quote do: `input`[`i`]
  else:
    for i in 0..<count: result.add quote do: `input`[`i`]

## count == 0 のとき unpackしない(seq)
## count >  0 のとき count個分 unpack した結果の tuple を返す
type UnselectableTypeError = object of Exception
template input*(typ: typedesc; count: Natural = 0): untyped =
  let line = stdin.readLine.split
  when count == 0:
    when typ is int:    line.map(parseInt)
    elif typ is float:  line.map(parseFloat)
    elif typ is string: line
    else: raise newException(UnselectableTypeError, "You selected a type other than int, float or string")
  else:
    when typ is int:    line.map(parseInt).unpack(count)
    elif typ is float:  line.map(parseFloat).unpack(count)
    elif typ is string: line.unpack(count)
    else: raise newException(UnselectableTypeError, "You selected a type other than int, float or string")

template inputs*(typ: typedesc; count = 0; rows = 1): untyped =
  (1..rows).mapIt(input(typ, count))

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
template secretEcho*(x: varargs[string, `$`]) =
  for v in x:
    stderr.write(v)
  stderr.writeLine ""

template secretEcho*[T](x: seq[seq[T]]) =
  for v in x: secretEcho v

template secretEcho*(x: seq[string]) =
  for v in x: secretEcho v

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
from sequtils import newSeqWith
import queues
from math import sum
from strutils import count

const
  dx = [1, 0, -1, 0]
  dy = [0, 1, 0, -1]

let
  (H, W) = input(int, 2)
  s = (1..H).mapIt(input(string, 1))

var
  maze = newSeqWith(H, newSeqWith(W, -1))
  q = initQueue[tuple[x, y: int]]()
q.enqueue((0, 0))
maze[0][0] = 1

while q.len > 0:
  let v = q.dequeue
  for i, _ in dx:
    let
      x = v.x + dx[i]
      y = v.y + dy[i]
    if 0 <= x and x < W and 0 <= y and y < H:
      if s[y][x] == '.' and maze[y][x] < 0:
        maze[y][x] = maze[v.y][v.x] + 1
        q.enqueue((x, y))

if maze[^1][^1] < 0:
  echo -1
else:
  echo H * W - maze[^1][^1] - s.mapIt(it.count('#')).sum

Submission Info

Submission Time
Task D - Grid Repainting
User nimon
Language Nim (0.13.0)
Score 400
Code Size 2361 Byte
Status AC
Exec Time 1 ms
Memory 380 KB

Compile Error

Hint: system [Processing]
Hint: Main [Processing]
Hint: sequtils [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: macros [Processing]
Hint: queues [Processing]
Hint: math [Processing]
Hint: times [Processing]
lib/pure/collections/sequtils.nim(591, 11) Hint: 'it' is declared but not used [XDeclaredButNotUsed]
Hint:  [Link]
Hint: operation successful (15904 lines compiled; 2.085 sec total; 17.174MB; Release Build) [SuccessX]

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 20
Set Name Test Cases
Sample s1.txt, s2.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
in01.txt AC 1 ms 256 KB
in02.txt AC 1 ms 256 KB
in03.txt AC 1 ms 256 KB
in04.txt AC 1 ms 256 KB
in05.txt AC 1 ms 256 KB
in06.txt AC 1 ms 256 KB
in07.txt AC 1 ms 256 KB
in08.txt AC 1 ms 256 KB
in09.txt AC 1 ms 256 KB
in10.txt AC 1 ms 256 KB
in11.txt AC 1 ms 256 KB
in12.txt AC 1 ms 256 KB
in13.txt AC 1 ms 256 KB
in14.txt AC 1 ms 256 KB
in15.txt AC 1 ms 380 KB
in16.txt AC 1 ms 380 KB
in17.txt AC 1 ms 380 KB
in18.txt AC 1 ms 380 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB