結果

問題 No.107 モンスター
ユーザー orange orangeorange orange
提出日時 2023-10-14 23:28:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,330 bytes
コンパイル時間 922 ms
コンパイル使用メモリ 99,724 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-14 23:28:10
合計ジャッジ時間 2,452 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<climits>
#include<set>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<assert.h>
#include<numeric>
#include<bitset>

#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()

typedef long long ll;
using namespace std;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 62;
const double PI = 2 * acos(0.0);
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }

int N;
int D[20];
int dp[66000];
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> D[i];
	dp[0] = 100;

	for (int msk = 0; msk < 1 << N; msk++) {
		int physical = 100;
		if (dp[msk] == 0) continue;
		for (int i = 0; i < N; i++) if ((msk & 1 << i) && D[i] < 0) physical += 100;
		for (int i = 0; i < N; i++) {
			if (msk & 1 << i) continue;
			int status;
			if (0 < D[i]) {
				status = min(dp[msk] + D[i], physical);
			}
			else {
				status = max(0, dp[msk] + D[i]);
			}

			chmax(dp[msk + (1 << i)], status);
		}
	}

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