結果

問題 No.943 取り調べ
ユーザー coco18000coco18000
提出日時 2019-12-06 23:31:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 1,206 ms
コード長 1,298 bytes
コンパイル時間 1,780 ms
コンパイル使用メモリ 165,280 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 17:44:16
合計ジャッジ時間 3,985 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll X[20];
ll A[20];
bool U[20];

int main() {
    ll N;
    cin >> N;
    REP(i, N) {
        ll x = 0;
        REP(j, N) {
            ll a;
            cin >> a;
            x |= (a << j);
        }
        X[i] = x;
    }

    REP(i, N) {
        cin >> A[i];
    }

    ll ans = INF;
    ll p = pow(2, N);
    REP(i, p) {
        ll x = i;
        memset(U, 0, sizeof(U));
        ll num = 0;
        while (true) {
            bool exist = false;
            REP(j, N) {
                if (U[j])
                    continue;
                if ((X[j] & x) == X[j]) {
                    exist = true;
                    x |= (1LL << j);
                    num++;
                    U[j] = true;
                }
            }
            if (!exist)
                break;
        }
        if (num < N)
            continue;
        ll m = 0;
        REP(j, N) {
            if (((i >> j) & 1) == 1)
                m += A[j];
        }
        ans = std::min(ans, m);
    }
    cout << ans << endl;
    return 0;
}
0