結果

問題 No.107 モンスター
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-22 13:06:17
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 1,028 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 106,392 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-11 11:14:15
合計ジャッジ時間 2,028 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>

using namespace std;

int main(){

    long long N, mx, cnt;
    cin >> N;
    mx = 1LL<<N;
    vector<long long> D(N);
    for (int i=0; i<N; i++) cin >> D[i];

    vector<long long> dp(mx, -1e18);
    dp[0] = 100;

    for (int i=0; i<mx; i++){
        for (int j=0; j<N; j++){
            if (!(i & 1LL<<j)){
                if (D[j] < 0){
                    dp[i|(1LL<<j)] = max(dp[i|(1LL<<j)], dp[i]+D[j]);
                    if (dp[i|(1LL<<j)] <= 0) dp[i|(1LL<<j)] = -1e18;
                }
                else{
                    cnt = 0;
                    for (int k=0; k<N; k++) if ((i & 1LL<<k) && (D[k] < 0)) cnt++;
                    dp[i|(1LL<<j)] = max(dp[i|(1LL<<j)], min(dp[i]+D[j], (cnt+1) * 100));
                }
            }
        }
    }

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

    return 0;
}
0