結果
| 問題 |
No.107 モンスター
|
| コンテスト | |
| ユーザー |
wheson
|
| 提出日時 | 2018-05-02 22:09:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 5,000 ms |
| コード長 | 1,506 bytes |
| コンパイル時間 | 2,049 ms |
| コンパイル使用メモリ | 168,664 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-28 00:23:24 |
| 合計ジャッジ時間 | 3,252 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
//#define int long long
using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
/*************** using variables ***************/
int n;
vector<int> d;
int dp[1 << 17];
int max_health[1 << 17];
/**********************************************/
bool contain(int mask, int pos){
return ((mask & (1 << pos)) != 0);
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
d.assign(n, 0);
REP(i, n) cin >> d[i];
REP(i, (1 << 17)) dp[i] = 0;
REP(i, (1 << 17)) max_health[i] = 100;
dp[0] = 100;
for(int mask = 1; mask < (1 << n); mask++){
REP(i, n) if(contain(mask, i)){
if(dp[mask ^ (1 << i)] == 0) continue;
max_health[mask] = max_health[mask ^ (1 << i)];
int health = dp[mask ^ (1 << i)];
if(d[i] < 0){
health = max(health + d[i], 0);
if(health != 0) max_health[mask] += 100;
}else{
health = min(health + d[i], max_health[mask ^ (1 << i)]);
}
dp[mask] = max(dp[mask], health);
}
}
cout << dp[(1 << n) - 1] << endl;
}
wheson