結果
| 問題 | No.107 モンスター |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-29 10:48:55 |
| 言語 | C++17(gcc12) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 5,000 ms |
| コード長 | 967 bytes |
| 記録 | |
| コンパイル時間 | 1,023 ms |
| コンパイル使用メモリ | 112,780 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-03-08 21:45:14 |
| 合計ジャッジ時間 | 1,675 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | for (auto &&i : v) scanf("%d", &i);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (auto &&i : v) scanf("%d", &i);
vector<int> dp(1<<n, -INF<int>);
vector<int> maxhp(1 << n);
maxhp[0] = 100;
dp[0] = 100;
for (int i = 1; i < (1 << n); ++i) {
for (int j = 0; j < n; ++j) {
if(i & (1 << j)){
maxhp[i] = maxhp[i ^ (1 << j)] + 100*(v[j] < 0);
dp[i] = max(dp[i], min(maxhp[i], dp[i^(1<<j)]+v[j]));
if(dp[i] <= 0) dp[i] = -INF<int>;
}
}
}
cout << (dp.back() == -INF<int> ? 0 : dp.back()) << "\n";
return 0;
}