結果

問題 No.943 取り調べ
ユーザー r_ishidar_ishida
提出日時 2020-02-02 21:12:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 191 ms / 1,206 ms
コード長 667 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 81,676 KB
実行使用メモリ 75,584 KB
最終ジャッジ日時 2023-10-19 01:27:20
合計ジャッジ時間 2,711 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,436 KB
testcase_01 AC 39 ms
53,436 KB
testcase_02 AC 37 ms
53,436 KB
testcase_03 AC 39 ms
53,436 KB
testcase_04 AC 118 ms
75,356 KB
testcase_05 AC 104 ms
75,192 KB
testcase_06 AC 117 ms
75,348 KB
testcase_07 AC 39 ms
53,436 KB
testcase_08 AC 131 ms
75,388 KB
testcase_09 AC 90 ms
75,528 KB
testcase_10 AC 80 ms
75,440 KB
testcase_11 AC 84 ms
75,508 KB
testcase_12 AC 37 ms
53,436 KB
testcase_13 AC 46 ms
62,108 KB
testcase_14 AC 46 ms
59,976 KB
testcase_15 AC 38 ms
53,436 KB
testcase_16 AC 37 ms
53,436 KB
testcase_17 AC 90 ms
75,496 KB
testcase_18 AC 39 ms
53,436 KB
testcase_19 AC 48 ms
62,108 KB
testcase_20 AC 39 ms
53,436 KB
testcase_21 AC 37 ms
53,436 KB
testcase_22 AC 88 ms
75,480 KB
testcase_23 AC 191 ms
75,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
x = []
y = []
for i in range(n):
    tmp = list(map(int, input().split()))
    y.append(tmp)
    tmp2 = 0
    for j in range(n):
        tmp2 += y[i][j] * 2 ** j
    x.append(tmp2)
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
    l = i
    c = 0
    k = -1
    while k + 1 < n:
        k += 1
        if ((c >> k) & 1) == 1:
            continue
        if (l & x[k]) == x[k]:
            c |= 1 << k
            l |= 1 << k
            k = -1

    if c == (1 << n) - 1:
        ans = tmp
print(ans)
0