結果

問題 No.689 E869120 and Constructing Array 3
ユーザー siman
提出日時 2023-01-25 12:50:24
言語 Ruby
(3.4.1)
結果
AC  
実行時間 110 ms / 1,000 ms
コード長 473 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-06-26 17:54:14
合計ジャッジ時間 3,946 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

K = gets.to_i

def solver(k)
  if k < 5050
    n = (1..100).find { |x| (1..x).sum > k } - 1
    ans = [1] * n + [2] + [8]
    remain = k - (1..n).sum

    remain.times do
      ans << 23
    end

    ans
  else
    ans = [1] * 100 + [2]
    remain = k - 5050

    (remain / 100).times do
      ans << 2
    end

    ans << 8
    remain %= 100
    remain.times do
      ans << 23
    end

    ans
  end
end

res = solver(K)
puts res.size
puts res.join(' ')
0