結果
問題 | No.107 モンスター |
ユーザー |
|
提出日時 | 2023-12-23 22:43:51 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 986 bytes |
コンパイル時間 | 3,135 ms |
コンパイル使用メモリ | 246,272 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-27 12:40:23 |
合計ジャッジ時間 | 4,046 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>#define rep(i,a,b) for(int i=a;i<b;i++)#define rrep(i,a,b) for(int i=a;i>=b;i--)#define fore(i,a) for(auto &i:a)#define all(x) (x).begin(),(x).end()using namespace std;typedef long long ll;typedef pair<int, int> P;int INF = 1e5;ll MOD = 1e3;int N;int main(){cin >> N;int monster[N];rep(i,0,N) cin >> monster[i];int hp[1<<N];rep(i,0,1<<N) hp[i] = 0;hp[0] = 100;int hp_max[1<<N];rep(i,0,1<<N) hp_max[i] = 0;hp_max[0] = 100;rep(i,1,1<<N) rep(j,0,N){if(i&(1<<j)){if(monster[j] < 0) hp_max[i] = hp_max[i-(1<<j)] + 100;else hp_max[i] = hp_max[i-(1<<j)];break;}}rep(i,0,1<<N) {if (hp[i] == 0) continue;rep(j,0,N) if((i & (1 << j)) == 0){int k;k = min(hp[i] + monster[j], hp_max[i+(1<<j)]);hp[i+(1<<j)] = max(hp[i+(1<<j)], k);}}cout << hp[(1<<N)-1]<< endl;}