結果
| 問題 |
No.943 取り調べ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-31 02:05:42 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 1,206 ms |
| コード長 | 691 bytes |
| コンパイル時間 | 2,932 ms |
| コンパイル使用メモリ | 247,608 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-31 02:05:46 |
| 合計ジャッジ時間 | 4,237 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N;
cin >> N;
vector<ll> v(N);
for(auto &i : v) {
for(ll j = 0; j < N; j++) {
ll x;
cin >> x;
i |= x << j;
}
}
vector<ll> A(N);
for(auto &i : A) { cin >> i; }
vector<ll> dp(1 << N, 1e18);
dp[0] = 0;
for(ll i = 0; i < 1 << N; i++) {
for(ll j = 0; j < N; j++) {
if(i >> j & 1) { continue; }
ll nx = i | 1 << j;
if((i & v[j]) == v[j]) { dp[nx] = min(dp[nx], dp[i]); }
else { dp[nx] = min(dp[nx], dp[i] + A[j]); }
}
}
cout << (dp.back() == 1e18 ? -1 : dp.back()) << "\n";
}