結果

問題 No.943 取り調べ
ユーザー 👑 rin204rin204
提出日時 2022-02-14 09:15:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 438 ms / 1,206 ms
コード長 936 bytes
コンパイル時間 1,008 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 77,436 KB
最終ジャッジ日時 2023-09-11 15:49:20
合計ジャッジ時間 5,762 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
70,816 KB
testcase_01 AC 67 ms
71,192 KB
testcase_02 AC 66 ms
70,844 KB
testcase_03 AC 65 ms
71,036 KB
testcase_04 AC 317 ms
76,844 KB
testcase_05 AC 147 ms
76,632 KB
testcase_06 AC 148 ms
77,176 KB
testcase_07 AC 68 ms
71,180 KB
testcase_08 AC 438 ms
76,972 KB
testcase_09 AC 128 ms
77,036 KB
testcase_10 AC 121 ms
77,436 KB
testcase_11 AC 121 ms
77,336 KB
testcase_12 AC 66 ms
70,916 KB
testcase_13 AC 73 ms
75,828 KB
testcase_14 AC 72 ms
75,904 KB
testcase_15 AC 66 ms
71,192 KB
testcase_16 AC 66 ms
71,124 KB
testcase_17 AC 148 ms
77,388 KB
testcase_18 AC 67 ms
71,464 KB
testcase_19 AC 82 ms
76,512 KB
testcase_20 AC 71 ms
75,752 KB
testcase_21 AC 66 ms
71,192 KB
testcase_22 AC 185 ms
77,204 KB
testcase_23 AC 341 ms
77,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
X = [list(map(int, input().split())) for _ in range(n)]
in_ = [0] *  n
AND = 0
lst_ = []
for i in range(n):
    tmp = 0
    for j in range(n):
        if X[i][j]:
            in_[i] += 1
            tmp += 1
    if tmp == 0:
        lst_.append(i)
        AND |= 1 << i
A = list(map(int, input().split()))
ans = 1 << 30

for bit in range(1 << n):
    if bit & AND != 0:
        continue
    tot = 0
    lst = lst_.copy()
    cnt = len(lst)
    in_2 = in_.copy()
    for i in range(n):
        if bit >> i & 1:
            tot += A[i]
            cnt += 1
            in_2[i] = 0
            lst.append(i)
    if tot >= ans:
        continue
    
    while lst:
        i = lst.pop()
        for j in range(n):
            if X[j][i]:
                in_2[j] -= 1
                if in_2[j] == 0:
                    lst.append(j)
                    cnt += 1
    
    if cnt == n:
        ans = min(ans, tot)
print(ans)
0