結果

問題 No.115 遠足のおやつ
ユーザー simansiman
提出日時 2015-01-13 02:47:46
言語 Ruby
(3.3.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 548 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 11,312 KB
実行使用メモリ 15,492 KB
最終ジャッジ日時 2023-09-04 05:08:59
合計ジャッジ時間 5,405 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
15,176 KB
testcase_01 AC 84 ms
15,120 KB
testcase_02 AC 85 ms
15,232 KB
testcase_03 AC 86 ms
15,260 KB
testcase_04 AC 85 ms
15,268 KB
testcase_05 AC 84 ms
15,100 KB
testcase_06 AC 86 ms
15,048 KB
testcase_07 AC 87 ms
15,308 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 85 ms
15,300 KB
testcase_14 AC 86 ms
15,128 KB
testcase_15 AC 84 ms
15,152 KB
testcase_16 AC 83 ms
15,180 KB
testcase_17 AC 83 ms
15,148 KB
testcase_18 AC 82 ms
15,152 KB
testcase_19 AC 83 ms
15,272 KB
testcase_20 AC 84 ms
15,268 KB
testcase_21 RE -
testcase_22 AC 81 ms
15,304 KB
testcase_23 AC 86 ms
15,156 KB
testcase_24 AC 83 ms
15,216 KB
testcase_25 AC 85 ms
15,096 KB
testcase_26 AC 84 ms
15,148 KB
testcase_27 AC 83 ms
15,240 KB
testcase_28 AC 84 ms
15,264 KB
testcase_29 AC 84 ms
15,152 KB
testcase_30 AC 85 ms
15,144 KB
testcase_31 AC 85 ms
15,120 KB
testcase_32 AC 86 ms
15,252 KB
testcase_33 AC 85 ms
15,128 KB
testcase_34 AC 82 ms
15,348 KB
testcase_35 AC 83 ms
15,244 KB
testcase_36 AC 86 ms
15,160 KB
testcase_37 AC 85 ms
15,176 KB
testcase_38 AC 85 ms
15,124 KB
testcase_39 AC 83 ms
15,152 KB
testcase_40 AC 83 ms
15,264 KB
testcase_41 AC 84 ms
15,244 KB
testcase_42 AC 82 ms
15,268 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:24: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

class A
  def initialize
    n, d, k = gets.chomp.split(' ').map(&:to_i)

    answer = [*(1..k-1)] + [d-(1..k-1).inject(:+)]

    diff = answer.last - n

    if diff > 0
      answer[-1] -= diff

      (k-2).downto(0) do |index|
        sub = [diff, (answer[index+1] - 1) - answer[index]].min
        answer[index] += sub
        diff -= sub

        break if diff.zero?
      end
    end

    if answer.inject(:+) == d and answer.uniq.size == k and answer.all?{|i| i > 0}
      puts answer.join(' ')
    else
      puts -1
    end
  end
end

A.new
0