結果

問題 No.943 取り調べ
ユーザー risujirohrisujiroh
提出日時 2019-12-09 02:24:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 264 ms / 1,206 ms
コード長 1,029 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 170,592 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-01 21:34:37
合計ジャッジ時間 5,092 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 264 ms
4,376 KB
testcase_05 AC 148 ms
4,376 KB
testcase_06 AC 149 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 258 ms
4,380 KB
testcase_09 AC 74 ms
4,380 KB
testcase_10 AC 77 ms
4,376 KB
testcase_11 AC 45 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 109 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 102 ms
4,380 KB
testcase_23 AC 213 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int inf = 0x3f3f3f3f;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector< vector<int> > x(n, vector<int>(n));
  for (auto&& v : x) {
    for (auto&& e : v) {
      cin >> e;
    }
  }
  vector<int> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  vector<int> dp(1 << n, inf);
  dp[0] = 0;
  for (int S = 1; S != 1 << n; ++S) {
    for (int i = 0; i != n; ++i) {
      if (S >> i & 1) {
        int cost = 0;
        for (int j = 0; j != n; ++j) {
          if (x[i][j] and ~S >> j & 1) {
            bool need = true;
            for (int k = 0; k != n; ++k) {
              if (k != i and S >> k & 1) {
                if (x[k][j]) {
                  need = false;
                  break;
                }
              }
            }
            if (need) {
              cost += a[j];
            }
          }
        }
        dp[S] = min(dp[S], dp[S ^ 1 << i] + cost);
      }
    }
  }
  cout << dp.back() << '\n';
}
0