結果
問題 |
No.943 取り調べ
|
ユーザー |
![]() |
提出日時 | 2019-12-26 16:31:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 431 ms / 1,206 ms |
コード長 | 1,308 bytes |
コンパイル時間 | 2,202 ms |
コンパイル使用メモリ | 200,760 KB |
最終ジャッジ日時 | 2025-01-08 15:12:52 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int>> x(n, vector<int>(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> x.at(i).at(j); } } vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a.at(i); } int mini = 100000 * 18; for (int bit = 0; bit < (1 << n); bit++) { vector<bool> ok(n); bool update = true; while (update) { update = false; for (int i = 0; i < n; i++) { if (ok.at(i)) continue; bool all = true; for (int j = 0; j < n; j++) { if (x.at(i).at(j) == 0) continue; all &= (bool)(bit & (1 << j)) | ok.at(j); } if (all) { update = true; ok.at(i) = true; } } } bool all = true; for (int i = 0; i < n; i++) { all &= ok.at(i); } if (all) { int sum = 0; for (int i = 0; i < n; i++) { sum += a.at(i) * (bool)(bit & (1 << i)); } mini = min(mini, sum); } } cout << mini << endl; }