結果

問題 No.115 遠足のおやつ
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2020-02-26 20:09:30
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 498 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 20,480 KB
最終ジャッジ日時 2024-04-21 16:33:12
合計ジャッジ時間 6,179 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
12,288 KB
testcase_01 AC 86 ms
12,160 KB
testcase_02 WA -
testcase_03 AC 77 ms
12,160 KB
testcase_04 AC 136 ms
14,976 KB
testcase_05 AC 79 ms
12,288 KB
testcase_06 AC 78 ms
12,160 KB
testcase_07 AC 78 ms
12,288 KB
testcase_08 AC 79 ms
12,288 KB
testcase_09 AC 84 ms
12,416 KB
testcase_10 AC 82 ms
12,544 KB
testcase_11 AC 78 ms
12,288 KB
testcase_12 AC 80 ms
12,160 KB
testcase_13 AC 78 ms
12,288 KB
testcase_14 AC 78 ms
12,160 KB
testcase_15 AC 112 ms
13,696 KB
testcase_16 AC 128 ms
14,464 KB
testcase_17 AC 91 ms
12,672 KB
testcase_18 AC 78 ms
12,160 KB
testcase_19 AC 80 ms
12,544 KB
testcase_20 AC 80 ms
12,288 KB
testcase_21 WA -
testcase_22 AC 103 ms
13,184 KB
testcase_23 AC 81 ms
12,160 KB
testcase_24 AC 102 ms
13,056 KB
testcase_25 AC 97 ms
12,672 KB
testcase_26 AC 84 ms
12,160 KB
testcase_27 AC 86 ms
12,416 KB
testcase_28 AC 85 ms
12,160 KB
testcase_29 AC 86 ms
12,288 KB
testcase_30 AC 98 ms
13,056 KB
testcase_31 AC 90 ms
12,288 KB
testcase_32 AC 126 ms
13,824 KB
testcase_33 AC 83 ms
12,416 KB
testcase_34 AC 138 ms
14,720 KB
testcase_35 AC 90 ms
12,800 KB
testcase_36 WA -
testcase_37 AC 118 ms
13,824 KB
testcase_38 WA -
testcase_39 AC 254 ms
20,480 KB
testcase_40 AC 77 ms
12,160 KB
testcase_41 AC 75 ms
12,160 KB
testcase_42 AC 83 ms
12,032 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, D, K = gets.split.map(&:to_i)
dp = Array.new(N + 1){ Array.new(K + 1){ Array.new(D + 1, -1) } }
dp[0][0][0] = 0

(1 .. N).each do |n|
  (1 .. K).each do |k|
    (1 .. D).each do |d|
      if d - n >= 0 && dp[n - 1][k - 1][d - n] >= 0
        dp[n][k][d] = n
      else
        dp[n][k][d] = dp[n - 1][k][d]
      end
    end
  end
end

d = D
i = dp[N][K][D]
items = []

while i > 0
  items << i
  d = d - i
  i = dp[i - 1][K - items.size][d]
end

puts items.empty? ? -1 : items.reverse.join(' ')
0