結果

問題 No.943 取り調べ
ユーザー kuhakukuhaku
提出日時 2019-12-15 02:30:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 1,206 ms
コード長 1,712 bytes
コンパイル時間 1,604 ms
コンパイル使用メモリ 170,336 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-10 20:16:21
合計ジャッジ時間 3,696 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//confilm 0LL and 1LL
//confilm cornercase such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n;
	cin >> n;
	vector<bitset<18> > b(n);
	rep(i, n) rep(j, n){
		ll f;
		cin >> f;
		b[i][j] = f;
	}
	Vec a(n);
	rep(i, n) cin >> a[i];

	ll ans = LINF;
	rep(bit, (1 << n)){
		bool flg = true;
		bitset<18> bits(bit), conf(0);
		while(flg){
			flg = false;
			rep(i, n){
				if(!conf[i] && ((conf|bits)&b[i]) == b[i]){
					conf[i] = 1;
					flg = true;
				}
			}
		}
		if(conf.count() == n){
			ll sum = 0;
			rep(i, n) if(bits[i]) sum += a[i];
			chmin(ans, sum);
		}
	}
	co(ans);

	return 0;
}
0