結果

問題 No.107 モンスター
ユーザー RyuRyu
提出日時 2018-06-17 16:33:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,294 bytes
コンパイル時間 1,516 ms
コンパイル使用メモリ 168,512 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 06:22:06
合計ジャッジ時間 3,031 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for (int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int dp[1 << 16];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<int> D(N);
    vector<bool> loc(N);
    REP(i, N)
    {
        cin >> D[i];

        if (D[i] < 0)
        {
            loc[i] = true;
        }
    }

    dp[0] = 100;

    REP(S, 1 << N)
    {
        int HP = 100;

        if(dp[S] == 0) continue;

        REP(i, N)
        {
            if(((S >> i) & 1) && loc[i])
            {
                HP += 100;
            }
        }


        REP(i, N)
        {
            if ((S >> i) & 1)
                continue;

            dp[S | 1 << i] = max(dp[S | 1 << i], (dp[S] + D[i] <= HP ? dp[S] + D[i] : HP));
        }
    }

    cout << dp[(1 << N) - 1] << endl;

    return 0;
}
0