結果

問題 No.107 モンスター
ユーザー Yuki InoueYuki Inoue
提出日時 2023-12-23 22:43:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 986 bytes
コンパイル時間 3,258 ms
コンパイル使用メモリ 245,432 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-23 22:43:56
合計ジャッジ時間 4,204 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int INF = 1e5;
ll MOD = 1e3;

int N;

int main(){
    cin >> N;
    int monster[N];
    rep(i,0,N) cin >> monster[i];

    int hp[1<<N];
    rep(i,0,1<<N) hp[i] = 0;
    hp[0] = 100;

    int hp_max[1<<N];
    rep(i,0,1<<N) hp_max[i] = 0;
    hp_max[0] = 100;

    rep(i,1,1<<N) rep(j,0,N){
        if(i&(1<<j)){
            if(monster[j] < 0) hp_max[i] = hp_max[i-(1<<j)] + 100;
            else hp_max[i] = hp_max[i-(1<<j)];
            break;
        }
    }

    rep(i,0,1<<N) {
        if (hp[i] == 0) continue;
        rep(j,0,N) if((i & (1 << j)) == 0){
            int k;
            k = min(hp[i] + monster[j], hp_max[i+(1<<j)]);
            hp[i+(1<<j)] = max(hp[i+(1<<j)], k);
        }
    }

    cout << hp[(1<<N)-1]<< endl;
}
0