結果

問題 No.943 取り調べ
ユーザー kimiyukikimiyuki
提出日時 2019-12-05 22:13:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 1,206 ms
コード長 920 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 200,716 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 17:13:21
合計ジャッジ時間 3,395 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 23 ms
4,380 KB
testcase_05 AC 29 ms
4,380 KB
testcase_06 AC 29 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 23 ms
4,380 KB
testcase_09 AC 7 ms
4,380 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 7 ms
4,376 KB
testcase_23 AC 28 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
using namespace std;
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }

int solve(int n, const vector<int32_t> & g, const vector<int> & a) {
    vector<int> dp(1 << n, INT_MAX);
    dp[0] = 0;
    REP3 (s, 1, 1 << n) {
        REP (i, n) if (s & (1 << i)) {
            int t = s ^ (1 << i);
            if (dp[t] == INT_MAX) continue;
            chmin(dp[s], dp[t] + ((g[i] | t) == t ? 0 : a[i]));
        }
    }
    return dp.back();
}

int main() {
    int n; cin >> n;
    vector<int32_t> g(n);
    REP (y, n) REP (x, n) {
        int z; cin >> z;
        if (z) {
            g[y] |= (1 << x);
        }
    }
    vector<int> a(n);
    REP (i, n) {
        cin >> a[i];
    }
    cout << solve(n, g, a) << endl;
    return 0;
}
0