結果

問題 No.943 取り調べ
ユーザー iqueue02iqueue02
提出日時 2019-12-06 12:06:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 181 ms / 1,206 ms
コード長 894 bytes
コンパイル時間 1,540 ms
コンパイル使用メモリ 169,852 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 19:49:46
合計ジャッジ時間 3,721 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9;
int main(){
  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> ok(n,0);
  rep(i,n) rep(j,n) if (x[i][j] == 1) ok[i] |= (1 << j);

  vector<int> dp(1<<n, INF);
  dp[0] = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    for (int j = 0; j < n; j++) {
      if (bit & (1 << j)) continue;
      int key = 0;
      for (int k = 0; k < n; k++) if (bit & (1 << k) && x[j][k]) key |= (1 << k);
      if (key == ok[j]) dp[bit | (1 << j)] = min(dp[bit | (1 << j)], dp[bit]);
      else dp[bit | (1 << j)] = min(dp[bit | (1 << j)], dp[bit] + a[j]);
    }
  }
  cout << dp[(1<<n)-1] << endl;
  return 0;
}
0