結果

問題 No.107 モンスター
ユーザー taka99_xyztaka99_xyz
提出日時 2022-12-22 20:36:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,590 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 201,824 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-11 11:21:04
合計ジャッジ時間 3,238 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int n;
  cin >> n;
  vi d(n);
  REP(i,n)cin >> d[i];

  int S = (1<<n);
  vi dp(S,-1);
  dp[0] = 100;

  vi lv(S,1);
  REP(s, S){
    REP(i,n){
      if((s >> i) & 1 && d[i] < 0){
        lv[s]++;
      }
    }
  }

  REP(s, S){
    if(dp[s]==-1)continue;
    REP(i, n){
      if((s >> i) & 1)continue;

      if(d[i]>0){
        chmax(dp[s | (1<<i)],  min(100 * lv[s], dp[s]+d[i]));
      }else{
        if(dp[s] + d[i] > 0){
          chmax(dp[ s | (1<<i)], dp[s] + d[i]);
        }
      }
    }
  }

  // REP(s,S){
  //   printf("%d %d\n",s,dp[s]);
  // }

  cout << max(0, dp[S-1]) << endl;


}

0