結果

問題 No.943 取り調べ
ユーザー face4face4
提出日時 2019-11-14 22:27:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 513 ms / 1,206 ms
コード長 683 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 75,568 KB
最終ジャッジ日時 2023-10-25 03:28:57
合計ジャッジ時間 3,707 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,616 KB
testcase_01 AC 36 ms
53,616 KB
testcase_02 AC 37 ms
53,616 KB
testcase_03 AC 37 ms
53,616 KB
testcase_04 AC 123 ms
75,524 KB
testcase_05 AC 513 ms
75,480 KB
testcase_06 AC 510 ms
75,484 KB
testcase_07 AC 36 ms
53,616 KB
testcase_08 AC 122 ms
75,520 KB
testcase_09 AC 93 ms
73,404 KB
testcase_10 AC 83 ms
70,544 KB
testcase_11 AC 75 ms
72,632 KB
testcase_12 AC 36 ms
53,616 KB
testcase_13 AC 50 ms
64,320 KB
testcase_14 AC 51 ms
64,324 KB
testcase_15 AC 41 ms
59,592 KB
testcase_16 AC 36 ms
53,616 KB
testcase_17 AC 84 ms
73,232 KB
testcase_18 AC 37 ms
53,616 KB
testcase_19 AC 48 ms
62,264 KB
testcase_20 AC 43 ms
59,712 KB
testcase_21 AC 37 ms
53,616 KB
testcase_22 AC 81 ms
72,600 KB
testcase_23 AC 284 ms
75,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

counton = [0]*n
for i in range(n):
    b = input().split()
    for j in range(n):
            counton[i] += 1<<j if b[j]=="1" else 0

a = list(map(int, input().split()))

ans = sum(a)

for i in range(2**n):
    tmp = 0
    for j in range(n):
        tmp += a[j] if ((i>>j)&1) == 1 else 0
    
    # 高速化出来る
    # if tmp >= ans:
    #     continue

    lie, confess, k = i, 0, -1
    while k+1 < n:
        k += 1
        if ((confess>>k)&1) == 1:
            continue
        if (lie&counton[k]) == counton[k]:
            confess |= 1<<k
            lie |= 1<<k
            k = -1
    
    if confess == (1<<n)-1:
        ans = min(ans, tmp)

print(ans)
0