結果

問題 No.688 E869120 and Constructing Array 2
ユーザー simansiman
提出日時 2021-02-18 07:54:57
言語 Ruby
(3.3.0)
結果
AC  
実行時間 91 ms / 1,000 ms
コード長 440 bytes
コンパイル時間 40 ms
コンパイル使用メモリ 11,480 KB
実行使用メモリ 15,332 KB
最終ジャッジ日時 2023-10-12 17:13:28
合計ジャッジ時間 2,164 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
15,332 KB
testcase_01 AC 89 ms
15,324 KB
testcase_02 AC 88 ms
15,308 KB
testcase_03 AC 89 ms
15,156 KB
testcase_04 AC 91 ms
15,300 KB
testcase_05 AC 90 ms
15,304 KB
testcase_06 AC 90 ms
15,208 KB
testcase_07 AC 90 ms
15,096 KB
testcase_08 AC 90 ms
15,096 KB
testcase_09 AC 90 ms
15,268 KB
testcase_10 AC 90 ms
15,192 KB
testcase_11 AC 90 ms
15,156 KB
testcase_12 AC 89 ms
15,244 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

K = gets.to_i
k = K
cnt = 0

if K == 0
  puts 1
  puts 0
  exit
end

while k % 2 == 0
  k /= 2
  cnt += 1
end

def f(n)
  n * (n - 1) / 2
end

cnt.downto(0) do |x|
  ng = 0
  ok = 10 ** 7

  while (ok - ng).abs >= 2
    n = (ok + ng) / 2

    if k <= f(n)
      ok = n
    else
      ng = n
    end
  end

  if f(ok) == k
    puts cnt + ok
    puts [[0] * cnt + [1] * ok].join(' ')
    exit
  end

  cnt -= 1
  k *= 2
end

0