結果

問題 No.688 E869120 and Constructing Array 2
ユーザー siman
提出日時 2021-02-18 07:47:00
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 420 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-09-14 15:43:14
合計ジャッジ時間 3,122 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 6 WA * 4
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

K = gets.to_i
k = K
cnt = 0

if K == 0
  puts 0
  exit
end

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

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

cnt.downto(1) 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

  k *= 2
end

0