結果

問題 No.943 取り調べ
ユーザー imoni_kawaiiimoni_kawaii
提出日時 2020-06-16 21:53:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 1,206 ms
コード長 1,211 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 202,080 KB
実行使用メモリ 7,704 KB
最終ジャッジ日時 2023-09-16 11:10:09
合計ジャッジ時間 3,331 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,480 KB
testcase_01 AC 4 ms
7,528 KB
testcase_02 AC 3 ms
7,448 KB
testcase_03 AC 3 ms
7,548 KB
testcase_04 AC 25 ms
7,460 KB
testcase_05 AC 28 ms
7,400 KB
testcase_06 AC 28 ms
7,612 KB
testcase_07 AC 4 ms
7,520 KB
testcase_08 AC 26 ms
7,608 KB
testcase_09 AC 9 ms
7,488 KB
testcase_10 AC 8 ms
7,408 KB
testcase_11 AC 6 ms
7,488 KB
testcase_12 AC 3 ms
7,704 KB
testcase_13 AC 3 ms
7,400 KB
testcase_14 AC 4 ms
7,532 KB
testcase_15 AC 4 ms
7,472 KB
testcase_16 AC 3 ms
7,468 KB
testcase_17 AC 9 ms
7,476 KB
testcase_18 AC 4 ms
7,408 KB
testcase_19 AC 3 ms
7,528 KB
testcase_20 AC 3 ms
7,412 KB
testcase_21 AC 3 ms
7,516 KB
testcase_22 AC 8 ms
7,476 KB
testcase_23 AC 27 ms
7,408 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; }

int dp[1<<20];

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;
  }
  rep(S, 1<<20) dp[S] = INF;
  dp[0] = 0;
  rep(S, 1<<n) {
    if(dp[S] == INF) continue;
    rep(i, n) {
      if(S>>i&1) continue;
      int d = ((S&mask[i]) == mask[i] ? 0 : a[i]);
      chmin(dp[S|1<<i], dp[S]+d);
    }
  }
  cout << dp[(1<<n)-1] << '\n';
  return 0;
}
0