結果

問題 No.1690 Power Grid
ユーザー 👑 kmjpkmjp
提出日時 2021-09-24 22:13:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 125 ms / 3,000 ms
コード長 1,482 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 201,080 KB
実行使用メモリ 5,612 KB
最終ジャッジ日時 2023-09-18 21:32:05
合計ジャッジ時間 5,246 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 124 ms
5,424 KB
testcase_07 AC 124 ms
5,488 KB
testcase_08 AC 124 ms
5,408 KB
testcase_09 AC 124 ms
5,464 KB
testcase_10 AC 124 ms
5,572 KB
testcase_11 AC 124 ms
5,408 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 14 ms
4,384 KB
testcase_15 AC 125 ms
5,432 KB
testcase_16 AC 124 ms
5,412 KB
testcase_17 AC 59 ms
4,600 KB
testcase_18 AC 28 ms
4,380 KB
testcase_19 AC 125 ms
5,412 KB
testcase_20 AC 125 ms
5,504 KB
testcase_21 AC 125 ms
5,412 KB
testcase_22 AC 124 ms
5,612 KB
testcase_23 AC 124 ms
5,612 KB
testcase_24 AC 125 ms
5,416 KB
testcase_25 AC 124 ms
5,424 KB
testcase_26 AC 124 ms
5,568 KB
testcase_27 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M,K;
ll dp[18][18];
int A[18];
ll dp2[1<<18];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>K;
	FOR(i,N) cin>>A[i];
	
	FOR(x,N) FOR(y,N) dp[x][y]=(x==y)?0:(1LL<<60);
	FOR(i,M) {
		cin>>x>>y>>k;
		dp[x-1][y-1]=dp[y-1][x-1]=k;
	}
	FOR(k,N) FOR(x,N) FOR(y,N) dp[x][y]=min(dp[x][y],dp[x][k]+dp[k][y]);
	
	FOR(i,1<<N) dp2[i]=1LL<<60;
	FOR(i,N) dp2[1<<i]=A[i];
	int mask;
	ll ret=1LL<<60;
	FOR(mask,1<<N) if(mask) {
		FOR(x,N) if((mask&(1<<x))==0) {
			ll ma=1LL<<60;
			FOR(y,N) if(mask&(1<<y)) ma=min(ma,dp[x][y]);
			dp2[mask|(1<<x)]=min(dp2[mask|(1<<x)],dp2[mask]+A[x]+ma);
		}
		if(__builtin_popcount(mask)==K) ret=min(ret,dp2[mask]);
	}
	
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0