結果

問題 No.943 取り調べ
ユーザー hipopohipopo
提出日時 2019-12-26 16:31:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 319 ms / 1,206 ms
コード長 1,308 bytes
コンパイル時間 2,024 ms
コンパイル使用メモリ 202,160 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 02:26:11
合計ジャッジ時間 4,575 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 319 ms
6,940 KB
testcase_05 AC 304 ms
6,940 KB
testcase_06 AC 312 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 313 ms
6,940 KB
testcase_09 AC 57 ms
6,944 KB
testcase_10 AC 52 ms
6,944 KB
testcase_11 AC 23 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 48 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 52 ms
6,940 KB
testcase_23 AC 291 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0