結果

問題 No.107 モンスター
ユーザー CleyLCleyL
提出日時 2022-08-18 15:58:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 201 ms / 5,000 ms
コード長 1,021 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 76,388 KB
実行使用メモリ 18,688 KB
最終ジャッジ日時 2024-04-16 00:23:14
合計ジャッジ時間 2,938 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 45 ms
9,984 KB
testcase_14 AC 90 ms
11,136 KB
testcase_15 AC 90 ms
11,008 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 18 ms
5,376 KB
testcase_18 AC 188 ms
7,040 KB
testcase_19 AC 188 ms
7,296 KB
testcase_20 AC 45 ms
10,496 KB
testcase_21 AC 44 ms
9,728 KB
testcase_22 AC 97 ms
16,000 KB
testcase_23 AC 201 ms
18,688 KB
testcase_24 AC 194 ms
12,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
int dp[17][(1<<17)][17];

int main(){
  int n;cin>>n;
  vector<int> X(n);
  int evilm = 0;
  for(int i = 0; n > i; i++){
    cin>>X[i];
    if(X[i] < 0)evilm++;
  }
  dp[0][0][0] = 100;
  for(int z = 0; n > z; z++){
    for(int i = 0; (1<<n) > i; i++){
      for(int j = 0; n > j; j++){
        if(i & (1<<j))continue;
        for(int k = 0; n > k; k++){
          if(dp[z][i][k] <= 0)continue;
          if(X[j] > 0){
            dp[z+1][i+(1<<j)][k] = min((k+1)*100,max(dp[z+1][i+(1<<j)][k],dp[z][i][k]+X[j]));
          }else{
            if(dp[z][i][k]+X[j] > 0)dp[z+1][i+(1<<j)][k+1] = max(dp[z+1][i+(1<<j)][k+1],dp[z][i][k]+X[j]);
          }
        }
      }
    }
  }
  // for(int i = 0; n > i; i++){
  //   for(int j = 0; (1<<n) > j; j++){
  //     for(int k = 0; n > k; k++){
  //       cout << "(" << i << "," << j << "," << k << "):" << dp[i][j][k] << " ";
  //     }
  //   }
  //   cout << endl;
  // }
  cout << dp[n][(1<<n)-1][evilm] << endl;
}
0