結果
問題 |
No.107 モンスター
|
ユーザー |
![]() |
提出日時 | 2017-01-10 18:42:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,719 bytes |
コンパイル時間 | 845 ms |
コンパイル使用メモリ | 95,728 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-18 00:25:38 |
合計ジャッジ時間 | 1,685 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 10 WA * 11 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <queue> #include <stack> #include <map> #include <algorithm> #include <sstream> #include <cmath> #include <set> #include <iomanip> #include <deque> #include <stdio.h> using namespace std; #define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++) #define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--) #define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end()) #define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end()) #define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end()) #define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val)) #define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val)) typedef long long ll; ll dp[1<<16]; ll hp[1<<16]; int main(){ int N; cin>>N; vector<int> D(N); REP(i,N)cin>>D[i]; REP(i,(1<<16))dp[i]=hp[i]=-1e9; dp[(1<<N)-1]=100; hp[(1<<N)-1]=100; for (int i=((1<<N)-1); i>=0; i-- ){ for (int j=0; j<N; j++ ) { int mask = (1<<j); int add = D[j]; if( (i|mask) > i ) { if ( add>0 ) { dp[i] = max(dp[i],min(dp[i|mask]+add,hp[i|mask])); hp[i] = hp[i|mask]; }else{ if ( dp[i|mask] + add>0 ) { if ( hp[i|mask] >= hp[i] ) { dp[i] = dp[i|mask] + add; hp[i] = hp[i|mask] + 100; } } } } } } if(dp[0]<0)cout<<0<<endl; else cout<<dp[0]<<endl; return 0; }