結果
| 問題 |
No.943 取り調べ
|
| コンテスト | |
| ユーザー |
けーむ
|
| 提出日時 | 2020-03-26 16:41:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,036 bytes |
| コンパイル時間 | 1,706 ms |
| コンパイル使用メモリ | 175,228 KB |
| 実行使用メモリ | 13,636 KB |
| 最終ジャッジ日時 | 2025-01-02 02:53:46 |
| 合計ジャッジ時間 | 11,156 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 TLE * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
ll n;
cin >> n;
vector<vector<ll>> to(n), rev(n);
rep(i, n) {
rep(j, n) {
ll x;
cin >> x;
if (x == 1) {
to[i].push_back(j);
rev[j].push_back(i);
}
}
}
vector<ll> a(n);
rep(i, n) cin >> a[i];
ll ans = LONG_LONG_MAX;
rep(bit, 1 << n) {
ll tmp = 0;
rep(i, n) {
if ((bit & (1 << i)) != 0) {
tmp += a[i];
}
}
vector<set<ll>> rem(n);
rep(i, n) {
rep(j, sz(to[i])) {
rem[i].insert(to[i][j]);
}
}
rep(i, n) {
if ((bit & (1 << i)) != 0) {
for(auto x : rev[i]) {
rem[x].erase(i);
}
}
}
while(true) {
bool update = false;
rep(i, n) {
if (sz(rem[i]) == 0) {
rep(j, n) {
if (rem[j].count(i) > 0) {
update = true;
rem[j].erase(i);
}
}
}
}
if (!update) break;
}
bool f = true;
rep(i, n) {
if (sz(rem[i]) != 0) {
f = false;
break;
}
}
if (!f) continue;
ans = min(ans, tmp);
}
cout << ans << endl;
return 0;
}
けーむ