結果

問題 No.943 取り調べ
ユーザー 東前頭十一枚目東前頭十一枚目
提出日時 2019-12-12 16:59:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 1,206 ms
コード長 759 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 165,900 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-07 11:04:47
合計ジャッジ時間 2,796 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n; cin >> n;
	int x[n] = {};
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			int xx; cin >> xx;
			x[i] |= (xx << j);
		}
	}
	int a[n]; for(int i = 0; i < n; ++i) cin >> a[i];
	int ans = 1e9;
	for(int mask = 0; mask < (1 << n); ++mask) {
		int tmp = 0;
		for(int i = 0; i < n; ++i) {
			if((mask >> i) & 1) tmp += a[i];
		}
		if(ans <= tmp) continue;
		int msk = mask;
		while(true) {
			bool update = false;
			for(int i = 0; i < n; ++i) {
				if((x[i] & msk) == x[i]) {
					if(not (msk >> i & 1)) {
						update = true;
						msk |= (1 << i);
					}
				}
			}
			if(not update) break;
		}
		if(msk == ((1 << n) - 1)) {
			ans = tmp;
		}
	}
	cout << ans << endl;
	return 0;
}
0