結果

問題 No.107 モンスター
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2015-11-04 13:17:50
言語 Ruby
(3.3.0)
結果
AC  
実行時間 275 ms / 5,000 ms
コード長 866 bytes
コンパイル時間 465 ms
コンパイル使用メモリ 11,208 KB
実行使用メモリ 16,360 KB
最終ジャッジ日時 2023-08-27 05:41:58
合計ジャッジ時間 4,794 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,252 KB
testcase_01 AC 84 ms
15,144 KB
testcase_02 AC 85 ms
15,068 KB
testcase_03 AC 84 ms
15,332 KB
testcase_04 AC 84 ms
15,232 KB
testcase_05 AC 83 ms
15,256 KB
testcase_06 AC 83 ms
14,996 KB
testcase_07 AC 83 ms
15,064 KB
testcase_08 AC 83 ms
15,268 KB
testcase_09 AC 85 ms
15,236 KB
testcase_10 AC 84 ms
14,992 KB
testcase_11 AC 83 ms
15,072 KB
testcase_12 AC 83 ms
15,068 KB
testcase_13 AC 133 ms
15,484 KB
testcase_14 AC 195 ms
15,596 KB
testcase_15 AC 195 ms
15,652 KB
testcase_16 AC 84 ms
15,100 KB
testcase_17 AC 103 ms
15,164 KB
testcase_18 AC 227 ms
16,200 KB
testcase_19 AC 224 ms
16,304 KB
testcase_20 AC 140 ms
15,540 KB
testcase_21 AC 130 ms
15,376 KB
testcase_22 AC 184 ms
15,664 KB
testcase_23 AC 275 ms
16,056 KB
testcase_24 AC 245 ms
16,360 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# Here your code !

n = gets.to_i
S = 1 << n
D = gets.split.map(&:to_i)
HP = Array.new(S, 0)
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