結果

問題 No.943 取り調べ
ユーザー chocopuuchocopuu
提出日時 2019-12-06 01:46:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 1,206 ms
コード長 1,239 bytes
コンパイル時間 4,635 ms
コンパイル使用メモリ 169,776 KB
実行使用メモリ 7,304 KB
最終ジャッジ日時 2023-08-24 19:33:54
合計ジャッジ時間 3,069 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,376 KB
testcase_04 AC 39 ms
7,296 KB
testcase_05 AC 46 ms
7,268 KB
testcase_06 AC 46 ms
7,296 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 39 ms
7,172 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 12 ms
4,376 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 11 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 11 ms
4,380 KB
testcase_23 AC 45 ms
7,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#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 FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
constexpr long long INF = 1e18;
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)

int dp[1ll << 18];

signed main(){
	IOS();
	int N;
	cin >> N;
	vector<vector<int>>x(N,vector<int>(N));
	REP(i,N)REP(j,N)cin>>x[i][j];
	vector<int>a(N);
	REP(i,N)cin>>a[i];
	vector<int>sum(1ll << N);
	REP(i,1ll<<N){
		int t = 0;
		REP(j,N){
			if(i & (1ll << j))t += a[j];
		}
		sum[i] = t;
	}
	vector<int>bit(N);
	REP(i,N){
		REP(j,N){
			if(x[i][j])bit[i] |= 1ll << j;
		}
	}
	REP(i,1ll<<N)dp[i] = INF;
	REP(i,1ll<<N){
		CHMIN(dp[i],sum[i]);
		REP(j,N){
			if(i&(1ll<<j))continue;
			if((bit[j]&i)==bit[j])CHMIN(dp[i^(1ll<<j)],dp[i]);
		}
	}
	cout<<dp[(1ll<<N)-1]<<endl;
	/*REP(i,1ll<<N){
		cout<<i<<" "<<dp[i]<<endl;
	}*/
}
0