結果

問題 No.107 モンスター
ユーザー tactac
提出日時 2019-04-27 12:28:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,402 bytes
コンパイル時間 963 ms
コンパイル使用メモリ 100,700 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 11:15:37
合計ジャッジ時間 1,995 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<list>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {1, 1, 0, -1, -1, 0};
int dx[] = {1, 0, -1, -1, 0, 1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

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

    rep(i, (1 << n)) dp[i] = -inf;
    dp[0] = 100;
    int limit[1 << n];
    limit[0] = 100;
    rep(i, (1 << n)) {
        if (dp[i] <= 0) continue;
        rep(j, n) {
            if (!(i & (1 << j))) { //which to add
                
                if (dp[i | 1 << j] <= min(limit[i], dp[i] + d[j])) {
                    dp[i | 1 << j] = min(limit[i], dp[i] + d[j]);
                    if (d[j] < 0) limit[i | 1 << j] = limit[i] + 100;
                    else limit[i | 1 << j] = limit[i];
                }
            }
        }
    }
    //rep(i, (1 << n)) cout << dp[i] << " "; cout << endl;
    if (dp[(1 << n) - 1] > 0) cout << dp[(1 << n) - 1] << endl;
    else cout << 0 << endl;
}
0