結果
| 問題 |
No.107 モンスター
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-12 19:59:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 1,475 bytes |
| コンパイル時間 | 1,689 ms |
| コンパイル使用メモリ | 169,220 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-21 07:23:03 |
| 合計ジャッジ時間 | 2,682 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
if( x > v ){
x = v;
return 1;
}
return 0;
}
template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
if( x < v ){
x = v;
return 1;
}
return 0;
}
const int INF = 0x3f3f3f3f;
int N;
vi D;
void init(){
cin >> N;
D = vi( N );
for( int i = 0; i < N; ++i )
cin >> D[ i ];
}
vi dp;
void preprocess(){
dp = vi( 1 << N, -INF );
dp[ 0 ] = 100;
for( int i = 0; i < 1 << N; ++i )
if( dp[ i ] > 0 ){
int max_hp = 100;
for( int j = 0; j < N; ++j )
if( i & 1 << j )
if( D[ j ] < 0 )
max_hp += 100;
for( int j = 0; j < N; ++j )
if( ~i & 1 << j ){
if( D[ j ] < 0 ){
if( dp[ i ] + D[ j ] > 0 )
upmax( dp[ i | 1 << j ], dp[ i ] + D[ j ] );
} else{
upmax( dp[ i | 1 << j ], min( max_hp, dp[ i ] + D[ j ] ) );
}
}
}
}
void solve(){
if( dp[ ( 1 << N ) - 1 ] < 0 )
cout << 0 << endl;
else
cout << dp[ ( 1 << N ) - 1 ] << endl;
}
signed main(){
ios::sync_with_stdio( 0 );
init();
preprocess();
solve();
return 0;
}