結果
問題 | No.943 取り調べ |
ユーザー | coco18000 |
提出日時 | 2019-12-06 23:31:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 83 ms / 1,206 ms |
コード長 | 1,298 bytes |
コンパイル時間 | 1,372 ms |
コンパイル使用メモリ | 167,000 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-24 03:16:46 |
合計ジャッジ時間 | 2,497 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i)) #define REP(i, n) FOR(i,n,0) #define OF64 std::setprecision(10) const ll MOD = 1000000007; const ll INF = (ll) 1e15; ll X[20]; ll A[20]; bool U[20]; int main() { ll N; cin >> N; REP(i, N) { ll x = 0; REP(j, N) { ll a; cin >> a; x |= (a << j); } X[i] = x; } REP(i, N) { cin >> A[i]; } ll ans = INF; ll p = pow(2, N); REP(i, p) { ll x = i; memset(U, 0, sizeof(U)); ll num = 0; while (true) { bool exist = false; REP(j, N) { if (U[j]) continue; if ((X[j] & x) == X[j]) { exist = true; x |= (1LL << j); num++; U[j] = true; } } if (!exist) break; } if (num < N) continue; ll m = 0; REP(j, N) { if (((i >> j) & 1) == 1) m += A[j]; } ans = std::min(ans, m); } cout << ans << endl; return 0; }