結果

問題 No.2236 Lights Out On Simple Graph
ユーザー mkawa2mkawa2
提出日時 2023-03-04 12:05:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 902 ms / 4,000 ms
コード長 1,379 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 81,616 KB
実行使用メモリ 270,080 KB
最終ジャッジ日時 2023-10-18 04:19:03
合計ジャッジ時間 26,009 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,436 KB
testcase_01 AC 42 ms
55,436 KB
testcase_02 AC 43 ms
55,436 KB
testcase_03 AC 888 ms
262,924 KB
testcase_04 AC 670 ms
261,224 KB
testcase_05 AC 43 ms
55,436 KB
testcase_06 AC 772 ms
262,928 KB
testcase_07 AC 669 ms
267,640 KB
testcase_08 AC 42 ms
55,436 KB
testcase_09 AC 43 ms
55,436 KB
testcase_10 AC 208 ms
139,888 KB
testcase_11 AC 89 ms
74,704 KB
testcase_12 AC 294 ms
153,744 KB
testcase_13 AC 76 ms
77,344 KB
testcase_14 AC 521 ms
194,668 KB
testcase_15 AC 71 ms
74,288 KB
testcase_16 AC 84 ms
86,100 KB
testcase_17 AC 135 ms
108,536 KB
testcase_18 AC 60 ms
66,404 KB
testcase_19 AC 122 ms
104,268 KB
testcase_20 AC 421 ms
186,300 KB
testcase_21 AC 120 ms
104,284 KB
testcase_22 AC 882 ms
262,920 KB
testcase_23 AC 890 ms
262,928 KB
testcase_24 AC 545 ms
194,672 KB
testcase_25 AC 182 ms
139,148 KB
testcase_26 AC 886 ms
262,924 KB
testcase_27 AC 428 ms
186,308 KB
testcase_28 AC 653 ms
261,228 KB
testcase_29 AC 120 ms
104,284 KB
testcase_30 AC 888 ms
262,924 KB
testcase_31 AC 883 ms
262,928 KB
testcase_32 AC 867 ms
262,924 KB
testcase_33 AC 860 ms
262,928 KB
testcase_34 AC 902 ms
262,924 KB
testcase_35 AC 754 ms
263,196 KB
testcase_36 AC 492 ms
224,868 KB
testcase_37 AC 848 ms
262,928 KB
testcase_38 AC 314 ms
152,032 KB
testcase_39 AC 223 ms
108,044 KB
testcase_40 AC 295 ms
139,360 KB
testcase_41 AC 110 ms
95,904 KB
testcase_42 AC 301 ms
149,060 KB
testcase_43 AC 81 ms
76,776 KB
testcase_44 AC 551 ms
175,232 KB
testcase_45 AC 765 ms
263,748 KB
testcase_46 AC 631 ms
217,628 KB
testcase_47 AC 723 ms
270,080 KB
testcase_48 AC 699 ms
225,292 KB
testcase_49 AC 688 ms
267,636 KB
testcase_50 AC 71 ms
68,948 KB
testcase_51 AC 203 ms
138,108 KB
testcase_52 AC 77 ms
73,292 KB
testcase_53 AC 44 ms
55,436 KB
testcase_54 AC 408 ms
145,424 KB
testcase_55 AC 330 ms
131,116 KB
testcase_56 AC 280 ms
130,656 KB
testcase_57 AC 315 ms
131,380 KB
testcase_58 AC 265 ms
118,136 KB
testcase_59 AC 253 ms
121,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
md = 10**9+7
# md = 998244353

from collections import defaultdict

def mim(ab):
    res = defaultdict(lambda: inf)
    n = len(ab)
    pc = [0]*(1 << n)
    dp = [0]*(1 << n)
    res[0] = 0
    for s in range(1, 1 << len(ab)):
        i = s.bit_length()-1
        pc[s] = pc[s ^ 1 << i]+1
        dp[s] = dp[s ^ 1 << i]
        a, b = ab[i]
        dp[s] ^= 1 << a
        dp[s] ^= 1 << b
        res[dp[s]] = min(res[dp[s]], pc[s])
    return res

n, m = LI()
ab = LLI1(m)
c = sum(a << i for i, a in enumerate(LI()))
ll = mim(ab[:m//2])
rr = mim(ab[m//2:])

ans = inf
for l in ll:
    r = c ^ l
    if r in rr:
        ans = min(ans, ll[l]+rr[r])

if ans == inf: ans = -1
print(ans)
0