結果
問題 | No.107 モンスター |
ユーザー |
![]() |
提出日時 | 2019-03-30 17:32:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 5,000 ms |
コード長 | 729 bytes |
コンパイル時間 | 1,749 ms |
コンパイル使用メモリ | 196,756 KB |
最終ジャッジ日時 | 2025-01-07 00:39:29 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} //INSERT ABOVE HERE signed main(){ Int n; cin>>n; vector<Int> d(n); for(Int i=0;i<n;i++) cin>>d[i]; Int s=1<<n; vector<Int> cnt(s,0); for(Int b=0;b<s;b++) for(Int i=0;i<n;i++) if((b>>i)&1) cnt[b]+=d[i]<0; vector<Int> dp(s,0); dp[0]=100; for(Int b=0;b<s;b++){ chmin(dp[b],(cnt[b]+1)*100); if(dp[b]==0) continue; for(Int i=0;i<n;i++){ if((b>>i)&1) continue; chmax(dp[b|(1<<i)],dp[b]+d[i]); } } cout<<dp[s-1]<<endl; return 0; }