結果

問題 No.943 取り調べ
ユーザー nebukuro09nebukuro09
提出日時 2019-12-05 22:39:47
言語 D
(dmd 2.106.1)
結果
RE  
実行時間 -
コード長 1,104 bytes
コンパイル時間 707 ms
コンパイル使用メモリ 109,352 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-09-04 03:42:15
合計ジャッジ時間 1,863 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 1 ms
4,380 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 2 ms
4,380 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 2 ms
4,376 KB
testcase_17 RE -
testcase_18 AC 1 ms
4,376 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 1 ms
4,380 KB
testcase_22 RE -
testcase_23 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
}
0