結果

問題 No.3 ビットすごろく
ユーザー toshiro_yanagitoshiro_yanagi
提出日時 2018-06-16 17:00:57
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 613 bytes
コンパイル時間 2,995 ms
コンパイル使用メモリ 68,840 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-13 06:08:36
合計ジャッジ時間 12,678 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 70 ms
4,380 KB
testcase_04 AC 8 ms
4,376 KB
testcase_05 AC 309 ms
4,376 KB
testcase_06 AC 86 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 293 ms
4,380 KB
testcase_13 AC 52 ms
4,380 KB
testcase_14 AC 651 ms
4,376 KB
testcase_15 AC 1,002 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 663 ms
4,376 KB
testcase_23 AC 1,018 ms
4,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
4,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
4,376 KB
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 28) Warning: imported and not used: 'sets' [UnusedImport]
/home/judge/data/code/Main.nim(1, 18) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #

import strutils, sequtils, sets, algorithm
proc trfm(i: int): int = i.toBin(16).count('1')
let
  N = stdin.readLine.parseInt
var
  arr, mini1, mini2 = newSeq[int](N)
  x = 1
mini1 = @[0]
arr[0] = 1

proc go(x: int) =
  for i0 in mini1.sorted(cmp, Descending):
    var i = i0
    while true:
      let pre = i
      i += (i + 1).trfm * x
      if x == 1:
        if i >= N: break
      else:
        if i <= 0: break
      if arr[i] == 0:
        arr[i] = arr[pre] + 1
        mini2.add i
  if mini2.len == 0: echo -1; quit()
  swap(mini1, mini2)
  mini2 = @[]

while arr[^1] == 0:
  go(x)
  x *= -1

echo arr[^1]
0