結果

問題 No.943 取り調べ
ユーザー prd_xxxprd_xxx
提出日時 2019-12-06 20:07:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 839 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 10,736 KB
実行使用メモリ 12,648 KB
最終ジャッジ日時 2023-08-25 04:03:08
合計ジャッジ時間 3,056 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

N = int(input())
X = [tuple(map(int,input().split())) for i in range(N)]
A = list(map(int,input().split()))

oks = set()
visited = set()
def isok(b,i):
    if i in oks: return True
    if i in visited: return False
    visited.add(i)
    for j,x in enumerate(X[i]):
        if x==0 or b&(1<<j): continue
        if isok(b,j): continue
        return False
    oks.add(i)
    return True

ans = sum(A)
for b in range(1<<N):
    tmp = 0
    for i in range(N):
        if b&(1<<i): tmp += A[i]
    if tmp >= ans: continue
    oks = set()
    for i,row in enumerate(X):
        for j in range(N):
            if row[j] and b&(1<<j)==0:break
        else:
            oks.add(i)
    visited = set()
    for i in range(N):
        if i in oks: continue
        if isok(b,i): continue
        break
    else:
        ans = tmp
        
print(ans)
0