結果

問題 No.943 取り調べ
ユーザー simansiman
提出日時 2021-05-24 17:21:59
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 150 ms / 1,206 ms
コード長 1,269 bytes
コンパイル時間 3,883 ms
コンパイル使用メモリ 137,736 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 03:14:30
合計ジャッジ時間 5,127 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 30 ms
5,376 KB
testcase_05 AC 49 ms
5,376 KB
testcase_06 AC 50 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 30 ms
5,376 KB
testcase_09 AC 22 ms
5,376 KB
testcase_10 AC 19 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 1 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 1 ms
5,376 KB
testcase_17 AC 11 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 9 ms
5,376 KB
testcase_23 AC 150 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  int X[N][N];
  int values[N];
  memset(values, 0, sizeof(values));

  for (int i = 0; i < N; ++i) {
    int value = 0;
    for (int j = 0; j < N; ++j) {
      cin >> X[i][j];
      if (X[i][j] == 1) {
        value |= 1 << j;
      }
    }
    values[i] = value;
  }

  int A[N];
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  int min_cost = INT_MAX;
  int M = 1 << N;

  for (int mask = 0; mask < M; ++mask) {
    int cost = 0;
    int nmask = mask;

    for (int i = 0; i < N; ++i) {
      if (nmask >> i & 1) {
        cost += A[i];
      }
    }

    bool updated = true;

    for (int i = 0; i < N && updated; ++i) {
      updated = false;

      for (int j = 0; j < N; ++j) {
        int val = values[j];

        if ((val & nmask) == val) {
          nmask |= 1 << j;
          updated = true;
        }
      }

      if (nmask == M - 1) break;
    }

    if (nmask == M - 1) {
      min_cost = min(min_cost, cost);
    }
  }

  cout << min_cost << endl;

  return 0;
}
0