結果
| 問題 |
No.943 取り調べ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-05 22:39:47 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,104 bytes |
| コンパイル時間 | 804 ms |
| コンパイル使用メモリ | 123,176 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-22 03:23:09 |
| 合計ジャッジ時間 | 1,703 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 RE * 16 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;
void main() {
auto N = readln.chomp.to!int;
auto X = iota(N).map!(_ => readln.split.map!(to!int)).array;
auto A = new int[](N);
foreach (i; 0..N) foreach (j; 0..N) if (X[i][j]) A[i] |= 1 << j;
auto B = readln.split.map!(to!int).array;
int ans = 1 << 29;
foreach (i; 0..(1<<N)) {
int mask = i;
bool ok = false;
while (true) {
int premask = mask;
foreach (j; 0..N) if (!(mask & (1 << j))) {
if ((A[j] & mask) == A[j]) {
mask |= (1 << j);
}
}
if (mask == (1 << N) - 1) {
ok = true;
break;
}
if (mask == premask) {
break;
}
}
if (ok) {
ans = min(ans, iota(1<<N).filter!(j => (1 << j) & i).map!(j => B[j]).sum);
}
}
ans.writeln;
}