結果

問題 No.107 モンスター
ユーザー imulanimulan
提出日時 2016-07-15 04:34:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,340 bytes
コンパイル時間 1,446 ms
コンパイル使用メモリ 166,936 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 06:54:20
合計ジャッジ時間 2,519 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const int N=1<<16;

int main()
{
    int n;
    cin >>n;
    vector<int> d(n);
    rep(i,n) cin >>d[i];

    int dp[N]={0};
    dp[0]=100;

    rep(mask,1<<n)
    {
        if(dp[mask]<=0) continue;

        //最大体力
        int lim=100;
        rep(i,n)
        {
            if(mask>>i&1 && d[i]<0) lim+=100;
        }

        //printf("mask = %d, lim = %d\n", mask,lim);

        //次に戦う敵
        rep(i,n)
        {
            if(mask>>i&1) continue;

            if(d[i]>0)
            {
                int nx=min(lim,dp[mask]+d[i]);
                int nst=mask+(1<<i);
                dp[nst]=max(dp[nst],nx);
                //printf(" nst = %d\n", nst);
            }
            else
            {
                if(dp[mask]+d[i]>0)
                {
                    int nst=mask+(1<<i);
                    dp[nst]=max(dp[nst],dp[mask]+d[i]);
                    //printf(" nst = %d\n", nst);
                }
            }
        }
    }

    cout << dp[(1<<n)-1] << endl;
    return 0;
}
0