結果
問題 | No.943 取り調べ |
ユーザー |
![]() |
提出日時 | 2019-12-08 18:15:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 121 ms / 1,206 ms |
コード長 | 884 bytes |
コンパイル時間 | 1,437 ms |
コンパイル使用メモリ | 169,512 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-31 01:52:47 |
合計ジャッジ時間 | 3,043 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 1000000000; cin >> n; vector<int> x(n), a(n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int x_ij; cin >> x_ij; x.at(i) += x_ij << j; } } for (int i = 0; i < n; i++) { cin >> a.at(i); } for (int i = 0; i < 1 << n; i++) { int cache = i; for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { if ((cache & x.at(k)) == x.at(k)) { cache |= 1 << k; } } } if (cache == (1 << n) - 1) { int cost = 0; for (int j = 0; j < n; j++) { if (i & (1 << j)) cost += a.at(j); } ans = min(ans, cost); } } cout << ans << endl; }