結果
問題 | No.107 モンスター |
ユーザー |
|
提出日時 | 2021-08-22 17:52:58 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 255 ms / 5,000 ms |
コード長 | 680 bytes |
コンパイル時間 | 135 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-11-06 16:00:33 |
合計ジャッジ時間 | 3,192 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
n = int(input()) d = list(map(int, input().split())) INF = 10**19 dp = [-INF]*(1 << n) dp[0] = 100 for s in range(1 << n): if dp[s] <= 0: continue limit = 1 for j in range(n): if (s >> j) & 1 and d[j]<0: limit += 1 for v in range(n): # まだ戦っていない if (s >> v) & 1 == 0: # 正の値の時 if d[v] >= 0: dp[s | (1 << v)] = min( max(dp[s | (1 << v)], dp[s]+d[v]), limit*100) # 負の値の時 elif dp[s]+d[v] > 0: dp[s | (1 << v)] = max(dp[s | (1 << v)], dp[s]+d[v]) ans = max(0, dp[(1 << n)-1]) print(ans)