結果

問題 No.943 取り調べ
ユーザー 0w1
提出日時 2020-12-19 14:28:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 842 bytes
コンパイル時間 2,061 ms
コンパイル使用メモリ 198,588 KB
最終ジャッジ日時 2025-01-17 03:50:34
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  ios::sync_with_stdio(false);

  int N; { cin >> N; }

  vector<vector<int>> X(N, vector<int>(N)); {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        cin >> X[i][j];
      }
    }
  }

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

  int res = accumulate(A.begin(), A.end(), 0);
  for (int s = 0; s < 1 << N; ++s) {
    int cost = 0; {
      for (int i = 0; i < N; ++i) if (s >> i & 1) {
        cost += A[i];
      }
    }

    int t = s; {
      for (int i = 0; i < N; ++i) {
        bool ok = true;
        for (int j = 0; j < N; ++j) {
          ok &= (s >> j & 1) || !X[i][j];
        }
        t |= ok << i;
      }
    }
    
    if (t == (1 << N) - 1) res = min(res, cost);
  }

  cout << res << endl;
}

0