結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,192 KB
testcase_01 AC 81 ms
15,308 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 78 ms
15,356 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 77 ms
15,092 KB
testcase_09 AC 77 ms
15,148 KB
testcase_10 AC 78 ms
15,124 KB
testcase_11 WA -
testcase_12 AC 78 ms
15,164 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 189 ms
15,812 KB
testcase_16 AC 79 ms
15,028 KB
testcase_17 AC 100 ms
15,360 KB
testcase_18 AC 222 ms
16,372 KB
testcase_19 AC 225 ms
16,408 KB
testcase_20 AC 139 ms
15,536 KB
testcase_21 AC 127 ms
15,416 KB
testcase_22 WA -
testcase_23 AC 268 ms
16,384 KB
testcase_24 AC 241 ms
16,232 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