結果

問題 No.689 E869120 and Constructing Array 3
ユーザー simansiman
提出日時 2023-01-25 12:49:16
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 459 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 11,404 KB
実行使用メモリ 15,564 KB
最終ジャッジ日時 2023-09-09 00:45:46
合計ジャッジ時間 6,341 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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