結果

問題 No.943 取り調べ
ユーザー imoni_kawaiiimoni_kawaii
提出日時 2020-06-16 21:22:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 1,206 ms
コード長 1,279 bytes
コンパイル時間 2,336 ms
コンパイル使用メモリ 203,488 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-16 11:09:33
合計ジャッジ時間 4,343 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long; using ld = long double; using pll = pair<ll, ll>;
const int INF = 1<<30; const ll LINF = 1LL<<60; const ld PI = 3.1415926535897932;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }



signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<int>> x(n, vector<int>(n));
  rep(i, n) rep(j, n) cin >> x[i][j];
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> mask(n);
  rep(i, n) {
    int t = 0;
    rep(j, n) {
      if(x[i][j]) t |= 1<<j;
    }
    mask[i] = t;
  }
  int ans = INF;
  rep(S, 1<<n) {
    bool ok = true;
    int T = S;
    rep(i, n) {
      rep(j, n) {
        if((T&mask[j]) == mask[j]) {
          T |= 1<<j;
        }
      }
    }
    if(T == (1<<n)-1) {
      int sum = 0;
      rep(i, n) {
        if(S>>i&1) sum += a[i];
      }
      chmin(ans, sum);
    }
  }
  cout << ans << '\n';
  return 0;
}
0