結果

問題 No.107 モンスター
ユーザー data9824
提出日時 2015-06-24 13:29:54
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 849 bytes
コンパイル時間 494 ms
コンパイル使用メモリ 62,988 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-18 01:39:55
合計ジャッジ時間 1,348 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n;
vector<int> d;

int maxStamina(unsigned int bits) {
	int result = 100;
	for (int i = 0; i < n; ++i) {
		if ((bits & (1 << i)) && d[i] < 0) {
			result += 100;
		}
	}
	return result;
}

int main() {
	cin >> n;
	d.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> d[i];
	}
	vector<int> stamina(1 << n);
	stamina[0x0] = 100;
	for (unsigned int bits = 0x0; bits < (1U << n); ++bits) {
		if (stamina[bits] == 0) {
			continue;
		}
		for (int next = 0; next < n; ++next) {
			if ((bits | (1 << next)) != bits) {
				int nextStamina = min(max(0, stamina[bits] + d[next]), maxStamina(bits));
				unsigned int nextBits = bits | (1U << next);
				stamina[nextBits] = max(stamina[nextBits], nextStamina);
			}
		}
	}
	cout << stamina[(1 << n) - 1] << endl;
	return 0;
}
0