結果

問題 No.943 取り調べ
ユーザー QCFiumQCFium
提出日時 2019-12-14 12:52:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 1,206 ms
コード長 857 bytes
コンパイル時間 1,669 ms
コンパイル使用メモリ 171,540 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 11:51:17
合計ジャッジ時間 4,220 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	std::vector<int> hen[n], rev[n];
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (ri()) hen[i].push_back(j), rev[j].push_back(i);
	
	int a[n];
	for (auto &i : a) i = ri();
	int res = 1000000000;
	for (int i = 0; i < 1 << n; i++) {
		int tayo[n];
		std::queue<int> que;
		for (int j = 0; j < n; j++) {
			tayo[j] = (i >> j & 1) ? 0 : hen[j].size();
			if (!tayo[j]) que.push(j);
		}
		while (que.size()) {
			
			for (auto k : rev[que.front()]) if (!--tayo[k]) que.push(k);
			que.pop();
		}
		bool ok = true;
		for (int j = 0; j < n; j++) if (tayo[j] > 0) ok = false;
		if (ok) {
			int cost = 0;
			for (int j = 0; j < n; j++) if (i >> j & 1) cost += a[j];
			res = std::min(res, cost);
		}
	}
	std::cout << res << std::endl;
	return 0;
}
0