結果

問題 No.107 モンスター
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2015-11-04 13:16:34
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 887 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 11,248 KB
実行使用メモリ 16,240 KB
最終ジャッジ日時 2023-10-11 13:39:58
合計ジャッジ時間 4,393 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,128 KB
testcase_01 AC 81 ms
15,208 KB
testcase_02 AC 81 ms
15,040 KB
testcase_03 WA -
testcase_04 AC 80 ms
15,184 KB
testcase_05 AC 79 ms
15,356 KB
testcase_06 AC 80 ms
15,324 KB
testcase_07 AC 80 ms
15,152 KB
testcase_08 AC 80 ms
15,352 KB
testcase_09 AC 79 ms
15,172 KB
testcase_10 AC 80 ms
15,320 KB
testcase_11 WA -
testcase_12 AC 81 ms
15,328 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 194 ms
15,676 KB
testcase_16 AC 81 ms
15,212 KB
testcase_17 AC 102 ms
15,184 KB
testcase_18 AC 222 ms
16,156 KB
testcase_19 AC 222 ms
16,136 KB
testcase_20 AC 140 ms
15,464 KB
testcase_21 AC 130 ms
15,600 KB
testcase_22 WA -
testcase_23 AC 270 ms
16,116 KB
testcase_24 AC 240 ms
16,240 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# Here your code !

n = gets.to_i
S = 1 << n
D = gets.split.map(&:to_i)
HP = Array.new(S, -1)
HPMAX = Array.new(S, 100)
HP[0] = 100 # HP[s]はsのモンスターに出会った後の残HP
HPMAX[0] = 100 # HPMAX[s]はsのモンスターに出会った後の最大HP

S.times do |s|
    n.times do |i|
        mask = 1 << i
        if s & mask > 0 && D[i] < 0 
            HPMAX[s] += 100
        end
    end
    next if HP[s] < 0
    n.times do |i|
        mask = 1 << i
        if s & mask == 0 
            if D[i] >= 0
                hp = HP[s] + D[i] < HPMAX[s] ? HP[s] + D[i] : HPMAX[s]
                other = HP[s | mask]
                HP[s | mask] =  [hp, other].max
            else
                hp = HP[s] + D[i]
                other = HP[s | mask]
                HP[s | mask] = [hp, other].max
            end
        end
    end
end
puts HP[S - 1] < 0 ? 0 : HP[S - 1]
0