結果
問題 | No.107 モンスター |
ユーザー | rpy3cpp |
提出日時 | 2015-07-17 12:50:04 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 134 ms / 5,000 ms |
コード長 | 1,822 bytes |
コンパイル時間 | 190 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 15,616 KB |
最終ジャッジ日時 | 2024-05-10 04:38:35 |
合計ジャッジ時間 | 2,334 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
10,880 KB |
testcase_01 | AC | 39 ms
10,880 KB |
testcase_02 | AC | 37 ms
10,880 KB |
testcase_03 | AC | 30 ms
10,880 KB |
testcase_04 | AC | 33 ms
10,880 KB |
testcase_05 | AC | 32 ms
10,880 KB |
testcase_06 | AC | 31 ms
10,880 KB |
testcase_07 | AC | 32 ms
10,752 KB |
testcase_08 | AC | 31 ms
10,752 KB |
testcase_09 | AC | 32 ms
10,752 KB |
testcase_10 | AC | 36 ms
10,752 KB |
testcase_11 | AC | 32 ms
10,880 KB |
testcase_12 | AC | 31 ms
10,880 KB |
testcase_13 | AC | 38 ms
11,904 KB |
testcase_14 | AC | 132 ms
14,464 KB |
testcase_15 | AC | 134 ms
14,592 KB |
testcase_16 | AC | 33 ms
10,880 KB |
testcase_17 | AC | 36 ms
11,520 KB |
testcase_18 | AC | 49 ms
15,488 KB |
testcase_19 | AC | 47 ms
15,488 KB |
testcase_20 | AC | 39 ms
12,032 KB |
testcase_21 | AC | 37 ms
11,904 KB |
testcase_22 | AC | 122 ms
13,824 KB |
testcase_23 | AC | 50 ms
15,616 KB |
testcase_24 | AC | 48 ms
15,488 KB |
ソースコード
def read_data(): N = int(input()) Ds = list(map(int, input().split())) return N, Ds def solve(N, Ds): global memo, best_score, upper memo = [dict() for i in range(1 << N)] best_score = -1 remain = (1 << N) - 1 level = 100 power = 100 good = [d for d in Ds if d > 0] bad = [d for d in Ds if d < 0] good.sort() bad.sort(reverse=True) upper = upper_limit(level, power, remain, Ds) return dfs(level, power, remain, bad + good) def upper_limit(level, power, remain, Ds): Dds = [d for i, d in enumerate(Ds) if remain & (1 << i)] n_bad = len([1 for d in Dds if d < 0]) return min(power + sum(Dds), level + 100 * n_bad), n_bad def dfs(level, power, remain, Ds): global memo, best_score, upper if power in memo[remain]: return memo[remain][power] if remain == 0: return power if best_score == upper: return best_score limit, n_bad = upper_limit(level, power, remain, Ds) if limit <= best_score: return 0 if n_bad == 0: memo[remain][power] = limit return limit record = 0 for i, d in enumerate(Ds): idx = 1 << i if not (remain & idx) or power + d <= 0: continue if d > 0: if level == power: continue new_power = min(level, power + d) result = dfs(level, new_power, remain - idx, Ds) if result > record: record = result elif d < 0: result = dfs(level + 100, power + d, remain - idx, Ds) if result > record: record = result memo[remain][power] = record if record > best_score: best_score = record return record if __name__ == '__main__': N, Ds = read_data() print(solve(N, Ds))