結果

問題 No.689 E869120 and Constructing Array 3
ユーザー siman
提出日時 2023-01-25 12:49:16
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 459 bytes
コンパイル時間 731 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-06-26 17:52:20
合計ジャッジ時間 8,114 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 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.join(' ')
0