結果

問題 No.2236 Lights Out On Simple Graph
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-03-03 23:19:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,439 ms / 4,000 ms
コード長 886 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 81,680 KB
実行使用メモリ 175,748 KB
最終ジャッジ日時 2023-10-18 03:38:09
合計ジャッジ時間 44,831 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,492 KB
testcase_01 AC 38 ms
53,492 KB
testcase_02 AC 38 ms
53,492 KB
testcase_03 AC 1,431 ms
175,744 KB
testcase_04 AC 804 ms
128,252 KB
testcase_05 AC 39 ms
53,492 KB
testcase_06 AC 1,049 ms
175,744 KB
testcase_07 AC 1,138 ms
109,400 KB
testcase_08 AC 38 ms
53,492 KB
testcase_09 AC 38 ms
53,492 KB
testcase_10 AC 290 ms
118,676 KB
testcase_11 AC 133 ms
72,548 KB
testcase_12 AC 381 ms
118,676 KB
testcase_13 AC 80 ms
72,388 KB
testcase_14 AC 684 ms
128,252 KB
testcase_15 AC 72 ms
69,860 KB
testcase_16 AC 91 ms
74,512 KB
testcase_17 AC 170 ms
97,760 KB
testcase_18 AC 53 ms
64,336 KB
testcase_19 AC 139 ms
84,392 KB
testcase_20 AC 530 ms
128,196 KB
testcase_21 AC 143 ms
86,532 KB
testcase_22 AC 1,324 ms
175,744 KB
testcase_23 AC 1,289 ms
175,740 KB
testcase_24 AC 699 ms
128,256 KB
testcase_25 AC 214 ms
98,024 KB
testcase_26 AC 1,255 ms
175,740 KB
testcase_27 AC 505 ms
128,200 KB
testcase_28 AC 744 ms
128,252 KB
testcase_29 AC 141 ms
86,532 KB
testcase_30 AC 1,338 ms
175,744 KB
testcase_31 AC 1,334 ms
175,748 KB
testcase_32 AC 1,336 ms
175,744 KB
testcase_33 AC 1,340 ms
175,740 KB
testcase_34 AC 1,303 ms
175,740 KB
testcase_35 AC 1,247 ms
175,744 KB
testcase_36 AC 1,343 ms
175,744 KB
testcase_37 AC 1,286 ms
175,744 KB
testcase_38 AC 1,249 ms
118,208 KB
testcase_39 AC 1,109 ms
77,460 KB
testcase_40 AC 481 ms
100,668 KB
testcase_41 AC 132 ms
82,732 KB
testcase_42 AC 333 ms
98,024 KB
testcase_43 AC 82 ms
71,920 KB
testcase_44 AC 1,417 ms
130,620 KB
testcase_45 AC 1,365 ms
132,936 KB
testcase_46 AC 1,378 ms
130,620 KB
testcase_47 AC 1,188 ms
132,308 KB
testcase_48 AC 1,439 ms
175,744 KB
testcase_49 AC 1,284 ms
109,400 KB
testcase_50 AC 67 ms
66,400 KB
testcase_51 AC 240 ms
86,476 KB
testcase_52 AC 70 ms
68,588 KB
testcase_53 AC 38 ms
53,492 KB
testcase_54 AC 691 ms
118,416 KB
testcase_55 AC 1,232 ms
97,820 KB
testcase_56 AC 972 ms
83,292 KB
testcase_57 AC 1,059 ms
89,028 KB
testcase_58 AC 1,170 ms
86,536 KB
testcase_59 AC 1,137 ms
83,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
AB = [[int(x)-1 for x in input().split()] for i in range(m)]
C = list(map(int,input().split()))

ans = m+1

dic = {}
l,r = AB[:m//2],AB[m//2:]
# print(l)
# print(r)
base = 0
for c in C[::-1]:
    base <<= 1
    base |= c
# print(base)
ll = len(l)
for b in range(1<<ll):

    num = base
    count = 0
    for i,(x,y) in enumerate(l):
        if b >> i & 1:
            count += 1
            num ^= 1<<x
            num ^= 1<<y
    # print(num,count)
    if num in dic:
        dic[num] = min(dic[num],count)
    else:
        dic[num] = count

lr = len(r)
for b in range(1<<lr):
    
    num = 0
    count = 0
    for i,(x,y) in enumerate(r):
        if b >> i & 1:
            count += 1
            num ^= 1<<x
            num ^= 1<<y
    # print(num,count)
    if num in dic:
        ans = min(ans,count+dic[num])
if ans == m+1:
    ans = -1
print(ans)
0