結果

問題 No.107 モンスター
ユーザー fiord
提出日時 2015-08-13 23:38:17
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 661 bytes
コンパイル時間 1,406 ms
コンパイル使用メモリ 166,524 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-07-18 09:17:38
合計ジャッジ時間 8,105 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 9 TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int n;
int d[16];
int dp[1<<16];
int main(){
	cin>>n;
	for(int i=0;i<n;i++)	cin>>d[i];
	dp[0]=100;
	priority_queue<tuple<int,int,int> > pq;
	pq.push(make_tuple(100,100,0));
	while(!pq.empty()){
		auto cur=pq.top();	pq.pop();
		int l=get<0>(cur);
		int ml=get<1>(cur);
		int now=get<2>(cur);
		if(l>dp[now])	continue;
		for(int i=0;i<n;i++){
			if(now&(1<<i))	continue;
			if(dp[now|(1<<i)]<dp[now]+d[i]){
				dp[now|(1<<i)]=dp[now]+d[i];
				if(d[i]>0)	dp[now|(1<<i)]=min(dp[now|(1<<i)],ml);
				pq.push(make_tuple(dp[now|(1<<i)],(d[i]<0)?ml+100:ml,now|(1<<i)));
			}
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}
0