結果

問題 No.943 取り調べ
ユーザー りあんりあん
提出日時 2019-12-05 22:21:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 1,206 ms
コード長 733 bytes
コンパイル時間 2,546 ms
コンパイル使用メモリ 199,772 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 17:55:16
合計ジャッジ時間 3,010 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> b(n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int c;
            cin >> c;
            b[i] |= c << j;
        }
    }
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<int> dp(1 << n, M);
    dp[0] = 0;
    for (int i = 0; i < (1 << n); ++i) {
        for (int j = 0; j < n; ++j) {
            dp[i | 1 << j] = min(dp[i | 1 << j], dp[i] + ((i & b[j]) == b[j] ? 0 : a[j]));
        }
    }
    cout << dp[(1 << n) - 1] << '\n';
    return 0;
}
0