結果

問題 No.943 取り調べ
ユーザー granddaifukugranddaifuku
提出日時 2020-03-22 20:05:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 600 ms / 1,206 ms
コード長 1,676 bytes
コンパイル時間 1,966 ms
コンパイル使用メモリ 176,864 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 19:51:28
合計ジャッジ時間 5,693 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 487 ms
4,376 KB
testcase_05 AC 374 ms
4,376 KB
testcase_06 AC 382 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 600 ms
4,376 KB
testcase_09 AC 91 ms
4,376 KB
testcase_10 AC 92 ms
4,380 KB
testcase_11 AC 47 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 94 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 127 ms
4,376 KB
testcase_23 AC 448 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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), trust(n);
    rep (i, n) {
        rep (j, n) {
            int v;
            cin >> v;
            if (v) x[i][j] = true;
        }
    }
    rep (i, n) cin >> a[i];
    rep (i, n) rep (j, n) if (x[i][j]) trust[i]++;

    rep (bit, 1 << n) {
        int tmp = 0;
        queue<int> s;
        vector<vector<bool> > y(n, vector<bool>(n));
        vector<bool> checked(n);
        vector<int> cnt(n);

        rep (i, n) cnt[i] = trust[i];

        rep (i, n) {
            if (bit & (1 << i)) {
                cnt[i] = 0;
                tmp += a[i];
            }
            if (!cnt[i]) {
                s.push(i);
            }
        }
        if (tmp >= res) continue;
        while (!s.empty()) {
            int f = s.front();
            s.pop();
            if (checked[f]) continue;
            checked[f] = true;
            rep (i, n) {
                if (x[i][f] && !checked[i]) {
                    cnt[i]--;
                    if (!cnt[i]) s.push(i);
                }
            }
        }
        bool ok = true;
        rep (i, n) if (!checked[i]) ok = false;
        if (ok) res = min(res, tmp);
    }
    cout << res << endl;
    
    return 0;
}
0