結果

問題 No.115 遠足のおやつ
ユーザー simansiman
提出日時 2016-03-24 00:31:12
言語 Ruby
(3.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 939 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 14,848 KB
最終ジャッジ日時 2024-04-17 19:44:12
合計ジャッジ時間 6,452 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
12,160 KB
testcase_01 AC 91 ms
12,544 KB
testcase_02 WA -
testcase_03 AC 86 ms
12,416 KB
testcase_04 AC 234 ms
14,208 KB
testcase_05 AC 84 ms
12,288 KB
testcase_06 AC 84 ms
12,288 KB
testcase_07 AC 77 ms
12,160 KB
testcase_08 AC 79 ms
12,160 KB
testcase_09 AC 80 ms
12,416 KB
testcase_10 AC 81 ms
12,288 KB
testcase_11 AC 85 ms
12,160 KB
testcase_12 AC 78 ms
12,288 KB
testcase_13 AC 84 ms
12,160 KB
testcase_14 AC 92 ms
12,288 KB
testcase_15 AC 168 ms
12,928 KB
testcase_16 AC 212 ms
13,568 KB
testcase_17 AC 114 ms
12,672 KB
testcase_18 AC 77 ms
12,032 KB
testcase_19 AC 82 ms
12,288 KB
testcase_20 AC 84 ms
12,288 KB
testcase_21 AC 76 ms
12,160 KB
testcase_22 AC 125 ms
12,800 KB
testcase_23 AC 86 ms
12,288 KB
testcase_24 AC 122 ms
13,184 KB
testcase_25 AC 112 ms
12,416 KB
testcase_26 AC 89 ms
12,160 KB
testcase_27 AC 98 ms
12,672 KB
testcase_28 AC 91 ms
12,416 KB
testcase_29 AC 97 ms
12,288 KB
testcase_30 AC 123 ms
12,672 KB
testcase_31 AC 92 ms
12,416 KB
testcase_32 AC 183 ms
13,056 KB
testcase_33 AC 81 ms
12,160 KB
testcase_34 AC 223 ms
14,080 KB
testcase_35 AC 106 ms
12,672 KB
testcase_36 AC 114 ms
13,824 KB
testcase_37 AC 173 ms
12,672 KB
testcase_38 AC 364 ms
14,848 KB
testcase_39 AC 383 ms
14,848 KB
testcase_40 AC 79 ms
12,160 KB
testcase_41 AC 77 ms
12,288 KB
testcase_42 AC 83 ms
12,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:38: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

class Node
  attr_reader :value, :list

  def initialize(value = -1, list = [])
    @list = list.sort
    @value = value
  end
end

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

    dp = Array.new(k+1){ Array.new(d+1){ Node.new }}
    dp[0][0] = Node.new(0, [])

    1.upto(k) do |i|
      d.downto(0) do |j|
        if dp[i-1][j].value >= 0
          i.upto(n) do |k|
            next if dp[i-1][j].list.include?(k)

            value = dp[i-1][j].value + k

            next if value > d

            if dp[i][value].value == -1
              dp[i][value] = Node.new(value, dp[i-1][j].list + [k])
            elsif (dp[i][value].list <=> dp[i-1][j].list) > 0
              dp[i][value] = Node.new(value, dp[i-1][j].list + [k])
            end
          end
        end
      end
    end

    if dp[k][d].value == -1
      puts -1
    else
      puts dp[k][d].list.join(' ')
    end
  end
end

Yukicoder.new
0