結果

問題 No.2236 Lights Out On Simple Graph
ユーザー 👑 KazunKazun
提出日時 2023-03-03 22:02:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,487 ms / 4,000 ms
コード長 845 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 283,840 KB
最終ジャッジ日時 2023-10-18 02:04:37
合計ジャッジ時間 69,605 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,452 KB
testcase_01 AC 38 ms
53,452 KB
testcase_02 AC 39 ms
53,452 KB
testcase_03 AC 2,487 ms
281,652 KB
testcase_04 AC 1,237 ms
268,052 KB
testcase_05 AC 38 ms
53,452 KB
testcase_06 AC 2,051 ms
281,692 KB
testcase_07 AC 2,013 ms
283,188 KB
testcase_08 AC 40 ms
53,452 KB
testcase_09 AC 38 ms
53,452 KB
testcase_10 AC 397 ms
111,264 KB
testcase_11 AC 147 ms
75,832 KB
testcase_12 AC 561 ms
128,712 KB
testcase_13 AC 87 ms
81,048 KB
testcase_14 AC 1,181 ms
205,760 KB
testcase_15 AC 80 ms
79,992 KB
testcase_16 AC 104 ms
87,236 KB
testcase_17 AC 222 ms
96,244 KB
testcase_18 AC 53 ms
64,584 KB
testcase_19 AC 209 ms
94,164 KB
testcase_20 AC 855 ms
195,216 KB
testcase_21 AC 209 ms
94,168 KB
testcase_22 AC 2,374 ms
281,624 KB
testcase_23 AC 2,357 ms
281,624 KB
testcase_24 AC 1,174 ms
201,100 KB
testcase_25 AC 319 ms
115,328 KB
testcase_26 AC 2,338 ms
281,624 KB
testcase_27 AC 891 ms
195,224 KB
testcase_28 AC 1,313 ms
268,088 KB
testcase_29 AC 212 ms
94,168 KB
testcase_30 AC 2,363 ms
281,624 KB
testcase_31 AC 2,395 ms
281,624 KB
testcase_32 AC 2,424 ms
281,624 KB
testcase_33 AC 2,406 ms
281,624 KB
testcase_34 AC 2,435 ms
281,752 KB
testcase_35 AC 2,127 ms
275,356 KB
testcase_36 AC 1,654 ms
246,456 KB
testcase_37 AC 2,321 ms
281,752 KB
testcase_38 AC 1,335 ms
112,156 KB
testcase_39 AC 1,173 ms
77,632 KB
testcase_40 AC 652 ms
115,336 KB
testcase_41 AC 195 ms
87,696 KB
testcase_42 AC 540 ms
143,348 KB
testcase_43 AC 84 ms
77,856 KB
testcase_44 AC 1,795 ms
182,960 KB
testcase_45 AC 2,115 ms
283,840 KB
testcase_46 AC 1,966 ms
229,848 KB
testcase_47 AC 2,054 ms
274,884 KB
testcase_48 AC 2,241 ms
273,032 KB
testcase_49 AC 1,955 ms
283,212 KB
testcase_50 AC 70 ms
75,644 KB
testcase_51 AC 371 ms
102,860 KB
testcase_52 AC 78 ms
76,216 KB
testcase_53 AC 39 ms
53,452 KB
testcase_54 AC 977 ms
129,620 KB
testcase_55 AC 1,371 ms
98,452 KB
testcase_56 AC 1,274 ms
90,772 KB
testcase_57 AC 1,306 ms
104,668 KB
testcase_58 AC 1,288 ms
83,908 KB
testcase_59 AC 1,227 ms
83,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    N,M=map(int,input().split())
    a=[0]*M; b=[0]*M

    for j in range(M):
        a[j],b[j]=map(int,input().split())
        a[j]-=1; b[j]-=1

    c=list(map(int,input().split()))

    def bit(x,k):
        return (x>>k)&1

    inf=10**9
    def calc(F):
        X={}
        M=len(F)

        for S in range(1<<M):
            p=0
            cnt=0
            for k in range(M):
                if bit(S,k):
                    p^=(1<<a[F[k]])^(1<<b[F[k]])
                    cnt+=1
            if cnt<X.get(p,inf):
                X[p]=cnt
        return X

    P=calc(list(range(M//2)))
    Q=calc(list(range(M//2,M)))

    target=sum([1<<v for v in range(N) if c[v]==1])
    ans=min(P[p]+Q.get(p^target,inf) for p in P)
    return ans if ans<inf else -1

#==================================================
print(solve())
0