結果

問題 No.943 取り調べ
ユーザー りあん
提出日時 2019-12-05 22:21:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 1,206 ms
コード長 733 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 194,852 KB
最終ジャッジ日時 2025-01-08 08:47:37
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

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