結果
問題 | No.1430 Coup de Coupon |
ユーザー | material |
提出日時 | 2021-03-15 00:53:59 |
言語 | Ruby (3.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,567 bytes |
コンパイル時間 | 477 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 234,656 KB |
最終ジャッジ日時 | 2024-11-06 13:27:30 |
合計ジャッジ時間 | 5,229 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 90 ms
19,104 KB |
testcase_01 | AC | 91 ms
12,160 KB |
testcase_02 | AC | 93 ms
12,160 KB |
testcase_03 | AC | 120 ms
13,696 KB |
testcase_04 | AC | 104 ms
12,288 KB |
testcase_05 | AC | 105 ms
12,416 KB |
testcase_06 | TLE | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
コンパイルメッセージ
Main.rb:11: warning: assigned but unused variable - total Syntax OK
ソースコード
Greater = Proc.new {|a, b| b <=> a} Infinity = 1e+9.to_i def main(argv) (n, c) = gets.chomp.split(' ').map(&:to_i) ps = [0] * n n.times{|i| ps[i] = gets.chomp.to_i} ps.sort!(&Greater) total = ps.reduce(:+) cs1 = [] cs2 = [] c.times do |j| cc = gets.chomp.split(' ').map(&:to_i) if cc[0] == 1 then cs1.push(cc[1]) else # cc[0] == 2 cs2.push(cc[1]) end end cs1.sort!(&Greater) cs2.sort!(&Greater) dp = [nil] * (n + 1) (n + 1).times{|i| dp[i] = Hash.new} dp[0][{:c1 => 0, :c2 => 0}] = 0 n.times do |i| dp[i].each do |state, value| dp[i + 1][state] = value + ps[i] if state[:c1] < cs1.size then next_state = {:c1 => state[:c1] + 1, :c2 => state[:c2]} cost = [ps[i] - cs1[state[:c1]], 0].max next_value = value + cost if dp[i + 1][next_state] == nil then dp[i + 1][next_state] = next_value else dp[i + 1][next_state] = [dp[i + 1][next_state], next_value].min end end if state[:c2] < cs2.size then next_state = {:c1 => state[:c1], :c2 => state[:c2] + 1} cost = ps[i] - ((ps[i] / 100) * cs2[state[:c2]]) next_value = value + cost if dp[i + 1][next_state] == nil then dp[i + 1][next_state] = next_value else dp[i + 1][next_state] = [dp[i + 1][next_state], next_value].min end end end end min_cost = 1e+12.to_i dp[n].each{|state, value| min_cost = [min_cost, value].min} puts min_cost.to_s end main(ARGV) if self.to_s == 'main'