結果
| 問題 |
No.943 取り調べ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-22 13:56:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,857 bytes |
| コンパイル時間 | 2,257 ms |
| コンパイル使用メモリ | 179,664 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-12-24 17:28:25 |
| 合計ジャッジ時間 | 13,323 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 1 TLE * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)
typedef long long ll;
typedef long double ld;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(0);
int n, res = Inf;
cin >> n;
vector<vector<bool> > x(n, vector<bool>(n));
vector<int> a(n);
rep (i, n) {
rep (j, n) {
int v;
cin >> v;
if (v) x[i][j] = true;
}
}
rep (i, n) cin >> a[i];
bool all = true;
rep (i, n) {
rep (j, n) {
if (x[i][j]) all = false;
}
}
if (all) {
cout << 0 << endl;
return 0;
}
rep (bit, 1 << n) {
vector<int> sv;
queue<int> s;
vector<vector<bool> > y(n, vector<bool>(n));
vector<bool> checked(n);
rep (i, n) {
if (bit & (1 << i)) {
s.push(i);
sv.push_back(i);
}
}
while (!s.empty()) {
int f = s.front();
s.pop();
rep (i, n) y[i][f] = true;
rep (i, n) {
if (checked[i]) continue;
bool same = true;
rep (j, n) {
if (x[i][j] && !y[i][j]) same = false;
}
if (same) {
checked[i] = true;
s.push(i);
}
}
}
bool ok = true;
rep (i, n) if (!checked[i]) ok = false;
if (ok) {
int tmp = 0;
rep (i, sv.size()) tmp += a[sv[i]];
res = min(res, tmp);
}
}
cout << res << endl;
return 0;
}