Submission #4039026


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

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
let
  grid = @[input(int), input(int), input(int)]

var t = grid
for i, _ in grid:
  for j, _ in grid[i]:
    t[i][j] = grid[j][i]

var
  a: array[3, int]
  b: array[3, int]

for i, row in grid:
  a[i] = row.min

for i, col in t:
  if col[0] - a[0] == col[1] - a[1] and col[1] - a[1] == col[2] - a[2]:
    b[i] = col[0] - a[0]
  else:
    echo "No"
    quit()

echo "Yes"
secretEcho a
secretEcho b

Submission Info

Submission Time
Task C - Takahashi's Information
User nimon
Language Nim (0.13.0)
Score 0
Code Size 1995 Byte
Status CE

Compile Error

Hint: system [Processing]
Hint: Main [Processing]
Hint: sequtils [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: macros [Processing]
Main.nim(64, 12) Error: type mismatch: got (array[0..2, int])
but expected one of: 
system.$(x: T)
system.$(x: int)
system.$(x: cstring)
system.$(x: bool)
system.$(x: char)
system.$(x: float)
system.$(x: Enum)
system.$(x: seq[T])
system.$(x: int64)
system.$(x: uint64)
system.$(x: string)
system.$(x: set[T])
macros.$(s: NimSym)
macros.$(node: NimNode)
macros.$(i: NimIdent)