結果

問題 No.107 モンスター
ユーザー kkktymkkktym
提出日時 2019-09-26 00:46:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 623 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 63,016 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 05:26:21
合計ジャッジ時間 1,883 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  vector<int> hp(1<<n,100);
  vector<int> dp(1<<n,-1);

  dp[0] = 100;

  rep(S,1<<n){
    if(dp[S]<=0) continue;
    rep(i,n){
      if(!((S>>i)&1)){
	if(d[i]>=0){
	  dp[S|(1<<i)] = max(dp[S|(1<<i)],min(dp[S]+d[i],hp[S]));
	}
	else{
	  dp[S|(1<<i)] = max(dp[S|(1<<i)],dp[S]+d[i]);
	  hp[S|(1<<i)] = hp[S] + 100;
	}
      }
    }
  }
  cout << max(0,dp[(1<<n)-1]) << "\n";
  return 0;
}
0