結果

問題 No.1286 Stone Skipping
ユーザー yuruhiyayuruhiya
提出日時 2020-11-17 20:13:44
言語 Crystal
(1.11.2)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 488 bytes
コンパイル時間 22,023 ms
コンパイル使用メモリ 262,268 KB
実行使用メモリ 5,292 KB
最終ジャッジ日時 2023-09-13 12:36:40
合計ジャッジ時間 19,611 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,824 KB
testcase_01 AC 3 ms
4,800 KB
testcase_02 AC 9 ms
5,188 KB
testcase_03 AC 5 ms
5,140 KB
testcase_04 AC 4 ms
5,140 KB
testcase_05 AC 5 ms
5,256 KB
testcase_06 AC 5 ms
5,248 KB
testcase_07 AC 4 ms
5,276 KB
testcase_08 AC 7 ms
5,200 KB
testcase_09 AC 8 ms
5,232 KB
testcase_10 AC 7 ms
5,252 KB
testcase_11 AC 7 ms
5,284 KB
testcase_12 AC 7 ms
5,204 KB
testcase_13 AC 7 ms
5,232 KB
testcase_14 AC 7 ms
5,140 KB
testcase_15 AC 8 ms
5,224 KB
testcase_16 AC 7 ms
5,220 KB
testcase_17 AC 7 ms
5,224 KB
testcase_18 AC 3 ms
4,784 KB
testcase_19 AC 3 ms
4,812 KB
testcase_20 AC 7 ms
5,192 KB
testcase_21 AC 6 ms
5,224 KB
testcase_22 AC 8 ms
5,276 KB
testcase_23 AC 10 ms
5,264 KB
testcase_24 AC 16 ms
5,264 KB
testcase_25 AC 6 ms
5,192 KB
testcase_26 AC 6 ms
5,188 KB
testcase_27 AC 6 ms
5,292 KB
testcase_28 AC 8 ms
5,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

require "big"

def calc(n : BigInt, k : Int32)
  res = 0.to_big_i
  k.times do |i|
    return -1 if n == 0
    res += n
    n //= 2
  end
  return res
end

n = read_line.to_big_i
puts (1..64).reverse_each.map { |k|
  val = (1.to_big_i..n).bsearch { |first|
    calc(first, k) >= n
  }
  [val && calc(val, k) == n, val]
}.find { |v|
  v[0]
}.not_nil![1]
0