結果

問題 No.107 モンスター
ユーザー motimoti
提出日時 2015-06-27 03:00:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 931 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 74,576 KB
実行使用メモリ 8,036 KB
最終ジャッジ日時 2023-08-22 22:57:50
合計ジャッジ時間 2,063 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int dp[1<<17][19];

int main() {

  int N; cin >> N;
  int D[N];
  rep(i, N) { cin >> D[i]; }

  dp[0][1] = 100;
  for(int S=0; S<(1<<N); S++) {
    for(int W=1; W<18; W++) {
      if(dp[S][W] <= 0) { continue; }
      for(int i=0; i<N; i++) {
        if(!(S >> i & 1)) {
          if(D[i] < 0) {
            if(dp[S][W]+D[i] <= 0) { continue; }
            dp[S|(1<<i)][W+1] = max(dp[S|(1<<i)][W+1], dp[S][W]+D[i]);
          }
          else {
            dp[S|(1<<i)][W] = max(dp[S|(1<<i)][W], min(W*100, dp[S][W]+D[i]));
          }
        }
      }
    }
  }

  int ans = 0;
  REP(i,1,18) { ans = max(ans, dp[(1<<N)-1][i]); }
  cout << ans << endl;

  return 0;
}
0