結果

問題 No.107 モンスター
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2017-01-10 18:31:26
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 1,484 bytes
コンパイル時間 2,275 ms
コンパイル使用メモリ 148,580 KB
実行使用メモリ 7,212 KB
最終ジャッジ日時 2023-09-03 00:26:24
合計ジャッジ時間 3,183 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 14 ms
4,380 KB
testcase_14 AC 23 ms
6,056 KB
testcase_15 AC 24 ms
6,068 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 8 ms
4,384 KB
testcase_18 AC 60 ms
6,888 KB
testcase_19 AC 59 ms
6,912 KB
testcase_20 AC 11 ms
4,376 KB
testcase_21 AC 12 ms
4,388 KB
testcase_22 AC 31 ms
6,372 KB
testcase_23 AC 57 ms
7,212 KB
testcase_24 AC 63 ms
6,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }

void main() {
    int N; readf("%d\n", &N);
    auto D = readln.chomp.split(" ").map!(to!int).array;

    const INF = int.max / 8;

    int[int] memo;
    int f(int set) {
        if (set == 0) return 100;
        if (set in memo) return memo[set];

        int next_hp(int cur_hp, int mid, int bit) { // mid: monster id, bit: 蛟偵@縺溘Δ繝ウ繧ケ繧ソ繝シ縺ョid縺ョ髮・粋
            int max_hp = 100;
            if (D[mid] < 0) {
                return cur_hp + D[mid] <= 0 ? -INF : cur_hp + D[mid];
            } else {
                for (int i = 0; i < N; i++) {
                    if (bit & (1 << i)) {
                        if (D[i] < 0) max_hp += 100;
                    }
                }
                return min(cur_hp + D[mid], max_hp);
            }
            
        }

        int ans = -INF;
        for (int i = 0; i < N; i++) {
            if (set & (1 << i)) {
                int hp = next_hp(f(set - (1 << i)), i, set);
                ans = max(ans, hp);
            }
        }
        return memo[set] = ans;
    }
    writeln(max(0, f((1 << N) - 1)));
//    foreach (k, v; memo) {
//        log(k, " -> ", v);
//    }
}
0