結果

問題 No.107 モンスター
ユーザー ありあり
提出日時 2023-02-08 11:19:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,262 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 81,832 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 04:11:06
合計ジャッジ時間 1,909 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 9 ms
4,380 KB
testcase_19 AC 8 ms
4,380 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 AC 9 ms
4,384 KB
testcase_24 AC 9 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cassert>
#include <cmath>
#include <bitset>
using namespace std;

int n;
int d[18];
int dp[300000];
int hp[300000];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> d[i];

  hp[0] = 100;
  for (int s = 0; s < (1<<n); s++)
    for (int i = 0; i < n; i++)
      if (~s&(1<<i)) {
        if (d[i] < 0) hp[s|(1<<i)] = hp[s]+100;
        else hp[s|(1<<i)] = hp[s];
      }
  //for (int s = 0; s < (1<<n); s++) cout << "hp[" << bitset<4>(s) << "] = " << hp[s] << endl;
  
  //for (int s = 0; s < 300000; s++) dp[s] = -1;
  dp[0] = 100;
  for (int s = 0; s < (1<<n); s++) {
    if (dp[s] <= 0) continue;
    for (int i = 0; i < n; i++)
      if (~s&(1<<i)) {
        if (d[i] > 0) {
          int res = min(dp[s] + d[i], hp[s|(1<<i)]);
          dp[s|(1<<i)] = max(dp[s|(1<<i)], res);
        }
        else {
          int res = dp[s] + d[i];
          dp[s|(1<<i)] = max(dp[s|(1<<i)], res);
        }
      }
  }
  //for (int s = 0; s < (1<<n); s++) cout << "dp[" << bitset<4>(s) << "] = " << dp[s] << endl;
  //cout << (dp[(1<<n)-1] < 0 ? 0 : dp[(1<<n)-1]) << endl;
  cout << dp[(1<<n)-1] << endl;
}
0