結果

問題 No.943 取り調べ
ユーザー ransewhaleransewhale
提出日時 2019-12-08 07:18:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 1,206 ms
コード長 960 bytes
コンパイル時間 1,441 ms
コンパイル使用メモリ 166,472 KB
実行使用メモリ 5,680 KB
最終ジャッジ日時 2023-08-28 09:49:08
合計ジャッジ時間 3,429 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,500 KB
testcase_01 AC 3 ms
5,372 KB
testcase_02 AC 3 ms
5,520 KB
testcase_03 AC 3 ms
5,452 KB
testcase_04 AC 22 ms
5,368 KB
testcase_05 AC 24 ms
5,384 KB
testcase_06 AC 24 ms
5,440 KB
testcase_07 AC 3 ms
5,428 KB
testcase_08 AC 22 ms
5,576 KB
testcase_09 AC 8 ms
5,496 KB
testcase_10 AC 8 ms
5,436 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 3 ms
5,428 KB
testcase_13 AC 3 ms
5,404 KB
testcase_14 AC 3 ms
5,680 KB
testcase_15 AC 3 ms
5,456 KB
testcase_16 AC 3 ms
5,428 KB
testcase_17 AC 7 ms
5,540 KB
testcase_18 AC 3 ms
5,576 KB
testcase_19 AC 3 ms
5,352 KB
testcase_20 AC 3 ms
5,384 KB
testcase_21 AC 3 ms
5,572 KB
testcase_22 AC 7 ms
5,364 KB
testcase_23 AC 24 ms
5,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, char> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[1<<18],a[18];
int x,f[18];

int main(void){
	int n,i,j;
	ll ans = INFLL;
	bool flag;
	fill(&dp[1],&dp[1<<18],INFLL);
	cin >> n;
	for(i=0; i<n; ++i){
		for(j=0; j<n; ++j){
			cin >> x;
			f[i] += (x<<j);
		}
	}
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	for(i=0; i<(1<<n); ++i){
		flag = true;
		for(j=0; j<n; ++j){
			if((i&f[j])!=f[j]){
				flag = false;
				break;
			}
		}
		if(flag){
			ans = min(ans,dp[i]);
		}
		for(j=0; j<n; ++j){
			if(i&(1<<j)){
				continue;
			}
			dp[i+(1<<j)] = min(dp[i+(1<<j)],dp[i]+(((i&f[j])==f[j])?0ll:a[j]));
		}
	}
	cout << dp[(1<<j)-1] << endl;
	return 0;
}
0