結果

問題 No.943 取り調べ
ユーザー tanon710
提出日時 2020-05-04 22:06:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 646 ms / 1,206 ms
コード長 842 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 76,928 KB
最終ジャッジ日時 2024-06-25 00:55:00
合計ジャッジ時間 4,949 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
check=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    tmp=0
    for j in range(n):
        if check[i][j]==1:
            tmp+=2**(n-1-j)
    check[i]=tmp
cost=list(map(int,input().split()))
ans=10**18
for i in range(0,2**n):
    flag=format(i,'b')
    s=set()
    tmp=i
    for j in range(n):
        if (i>>j)&1:
            s.add(n-1-j)
    prev=len(s)
    for _ in range(n):
        if len(s)==n:
            break
        for j in range(n):
            if j in s:
                continue
            if (~tmp)&check[j]==0:
                s.add(j)
                tmp+=2**(n-1-j)
        if len(s)==prev:
            break
        prev=len(s)
    if len(s)==n:
        tmp=0
        for j in range(n):
            if (i>>j)&1:
                tmp+=cost[n-1-j]
        ans=min(ans,tmp)
print(ans)
0