Submission #3446461


Source Code Expand

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

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しない
# count >  0 のとき count個分 unpack した結果の tuple を返す
type UnselectableTypeError = object of Exception
template input*(typ: typedesc; count: static[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")

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
from sequtils import mapIt

let
  N = input(int, 1)
  a = (1..N).mapIt(input(int, 1))

var
  pushed = newSeq[bool](N)
  i = 0
  count = 0
while not pushed[i] and not pushed[1]:
  pushed[i] = true
  i = a[i] - 1
  count.inc

if pushed[1]:
  echo count - 1
else:
  echo -1

Submission Info

Submission Time
Task B - Trained?
User nimon
Language Nim (0.13.0)
Score 200
Code Size 1552 Byte
Status AC
Exec Time 41 ms
Memory 3316 KB

Compile Error

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

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 3
AC × 25
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 40 ms 3316 KB
02.txt AC 41 ms 3316 KB
03.txt AC 40 ms 3316 KB
04.txt AC 41 ms 3316 KB
05.txt AC 40 ms 3316 KB
06.txt AC 41 ms 3316 KB
07.txt AC 41 ms 3316 KB
08.txt AC 41 ms 3316 KB
09.txt AC 41 ms 3316 KB
10.txt AC 41 ms 3316 KB
11.txt AC 41 ms 3188 KB
12.txt AC 40 ms 3316 KB
13.txt AC 40 ms 3316 KB
14.txt AC 41 ms 3316 KB
15.txt AC 39 ms 3316 KB
16.txt AC 40 ms 3316 KB
17.txt AC 39 ms 3316 KB
18.txt AC 40 ms 3316 KB
19.txt AC 1 ms 256 KB
20.txt AC 1 ms 256 KB
21.txt AC 1 ms 256 KB
22.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB