結果

問題 No.943 取り調べ
ユーザー けーむけーむ
提出日時 2020-03-26 16:41:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,036 bytes
コンパイル時間 1,844 ms
コンパイル使用メモリ 179,904 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-08-30 13:11:52
合計ジャッジ時間 4,918 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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