結果

問題 No.10 +か×か
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-05-29 17:02:41
言語 Ruby
(3.2.2)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 385 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 11,500 KB
実行使用メモリ 279,448 KB
最終ジャッジ日時 2023-08-21 06:26:46
合計ジャッジ時間 15,992 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,248 KB
testcase_01 AC 78 ms
15,040 KB
testcase_02 AC 77 ms
15,064 KB
testcase_03 TLE -
testcase_04 AC 672 ms
43,088 KB
testcase_05 AC 83 ms
15,092 KB
testcase_06 TLE -
testcase_07 AC 1,737 ms
103,276 KB
testcase_08 AC 407 ms
35,052 KB
testcase_09 AC 569 ms
36,484 KB
testcase_10 AC 83 ms
15,440 KB
testcase_11 AC 82 ms
15,144 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
t = gets.to_i
a = gets.split.map(&:to_i)

dp = Array.new(n + 1){ Array.new(t + 1, "!") }
dp[1][a[0]] = ""
(1...n).each do |x|
  (0..t).each do |y|
    next if dp[x][y] == "!"
    dp[x + 1][y + a[x]] = [dp[x + 1][y + a[x]], dp[x][y] + "+"].max if y + a[x] <= t
    dp[x + 1][y * a[x]] = [dp[x + 1][y * a[x]], dp[x][y] + "*"].max if y * a[x] <= t
  end
end

puts dp[n][t]

0