結果

問題 No.107 モンスター
ユーザー fiordfiord
提出日時 2015-08-13 23:38:17
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 661 bytes
コンパイル時間 1,240 ms
コンパイル使用メモリ 153,316 KB
実行使用メモリ 11,472 KB
最終ジャッジ日時 2023-09-25 11:30:58
合計ジャッジ時間 8,178 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
11,472 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

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