結果
| 問題 |
No.107 モンスター
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-06 11:40:37 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 5,000 ms |
| コード長 | 936 bytes |
| コンパイル時間 | 977 ms |
| コンパイル使用メモリ | 119,052 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-12 04:11:04 |
| 合計ジャッジ時間 | 2,175 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;
void main()
{
auto n = readln.chomp.to!int;
auto di = readln.split.map!(to!int);
auto b = 0;
foreach (i; 0..n)
if (di[i] < 0) b |= (1 << i);
int calcMaxHp(int i) {
return 100 + (b & i).popcnt * 100;
}
int calcHp(int hp, int i, int j) {
auto d = di[j];
if (d > 0) {
return min(calcMaxHp(i), hp + d);
} else
return max(0, hp + d);
}
auto memo = new int[](1 << n);
memo[0] = 100;
foreach (i; 1..1 << n) {
auto maxHp = 0;
foreach (j; 0..n) {
if (i & (1 << j)) {
auto k = i ^ (1 << j);
if (memo[k] > 0) {
auto hp = calcHp(memo[k], k, j);
maxHp = max(maxHp, hp);
}
}
}
memo[i] = maxHp;
}
writeln(memo[$ - 1]);
}