結果

問題 No.943 取り調べ
ユーザー NOSSNOSS
提出日時 2019-12-31 18:55:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 252 ms / 1,206 ms
コード長 1,623 bytes
コンパイル時間 1,876 ms
コンパイル使用メモリ 171,496 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-30 03:16:12
合計ジャッジ時間 3,816 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<ll,P>;
using PP = pair<P ,P>;
constexpr ll MOD = 998244353;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


int main(){
    int n;
    cin >> n;
    vector<vector<int> > x(n, vector<int>(n));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin >> x[i][j];
        }
    }
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int ans = IINF;
    for(int S=0;S<1<<n;S++){
        int T = 0;
        bool update = true;
        while(update){
            update = false;
            for(int i=0;i<n;i++){
                if((T>>i)&1) continue;
                bool ok = true;
                for(int j=0;j<n;j++){
                    ok &= x[i][j]==0 || ((T>>j)&1) || ((S>>j)&1);
                }
                if(ok){
                    T |= 1<<i;
                    update = true;
                }
            }
        }
        if(T == (1<<n)-1){
            int cost = 0;
            for(int i=0;i<n;i++){
                if((S>>i)&1) cost += a[i];
            }
            ans = min(ans, cost);
        }
    }
    cout << ans << endl;
    return 0;
}
0