結果
問題 | No.2236 Lights Out On Simple Graph |
ユーザー | 👑 seekworser |
提出日時 | 2023-03-01 22:23:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,954 ms / 4,000 ms |
コード長 | 1,390 bytes |
コンパイル時間 | 375 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 298,880 KB |
最終ジャッジ日時 | 2024-09-16 20:17:54 |
合計ジャッジ時間 | 81,140 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
51,840 KB |
testcase_01 | AC | 41 ms
51,968 KB |
testcase_02 | AC | 42 ms
51,968 KB |
testcase_03 | AC | 2,733 ms
298,880 KB |
testcase_04 | AC | 1,169 ms
252,812 KB |
testcase_05 | AC | 41 ms
51,968 KB |
testcase_06 | AC | 1,995 ms
298,752 KB |
testcase_07 | AC | 1,902 ms
164,760 KB |
testcase_08 | AC | 40 ms
51,712 KB |
testcase_09 | AC | 40 ms
51,968 KB |
testcase_10 | AC | 562 ms
152,076 KB |
testcase_11 | AC | 303 ms
76,544 KB |
testcase_12 | AC | 650 ms
151,820 KB |
testcase_13 | AC | 123 ms
83,456 KB |
testcase_14 | AC | 1,289 ms
252,936 KB |
testcase_15 | AC | 101 ms
79,104 KB |
testcase_16 | AC | 132 ms
83,328 KB |
testcase_17 | AC | 355 ms
110,160 KB |
testcase_18 | AC | 66 ms
67,072 KB |
testcase_19 | AC | 204 ms
90,496 KB |
testcase_20 | AC | 1,162 ms
252,808 KB |
testcase_21 | AC | 206 ms
90,496 KB |
testcase_22 | AC | 2,662 ms
298,496 KB |
testcase_23 | AC | 2,662 ms
298,372 KB |
testcase_24 | AC | 1,339 ms
253,444 KB |
testcase_25 | AC | 356 ms
109,976 KB |
testcase_26 | AC | 2,606 ms
298,756 KB |
testcase_27 | AC | 1,175 ms
253,060 KB |
testcase_28 | AC | 1,341 ms
252,936 KB |
testcase_29 | AC | 202 ms
90,368 KB |
testcase_30 | AC | 2,636 ms
298,340 KB |
testcase_31 | AC | 2,668 ms
298,628 KB |
testcase_32 | AC | 2,755 ms
298,628 KB |
testcase_33 | AC | 2,663 ms
298,372 KB |
testcase_34 | AC | 2,641 ms
298,496 KB |
testcase_35 | AC | 2,528 ms
298,496 KB |
testcase_36 | AC | 2,954 ms
298,628 KB |
testcase_37 | AC | 2,688 ms
298,624 KB |
testcase_38 | AC | 2,696 ms
158,352 KB |
testcase_39 | AC | 2,257 ms
80,384 KB |
testcase_40 | AC | 970 ms
161,868 KB |
testcase_41 | AC | 202 ms
90,752 KB |
testcase_42 | AC | 571 ms
117,568 KB |
testcase_43 | AC | 130 ms
79,104 KB |
testcase_44 | AC | 2,399 ms
264,744 KB |
testcase_45 | AC | 2,284 ms
258,632 KB |
testcase_46 | AC | 2,318 ms
268,172 KB |
testcase_47 | AC | 2,069 ms
264,468 KB |
testcase_48 | AC | 2,720 ms
298,628 KB |
testcase_49 | AC | 2,014 ms
164,944 KB |
testcase_50 | AC | 118 ms
76,288 KB |
testcase_51 | AC | 446 ms
93,812 KB |
testcase_52 | AC | 104 ms
77,184 KB |
testcase_53 | AC | 42 ms
52,352 KB |
testcase_54 | AC | 1,113 ms
155,016 KB |
testcase_55 | AC | 2,039 ms
111,600 KB |
testcase_56 | AC | 1,648 ms
98,176 KB |
testcase_57 | AC | 1,816 ms
117,984 KB |
testcase_58 | AC | 1,821 ms
96,752 KB |
testcase_59 | AC | 1,830 ms
95,712 KB |
ソースコード
MSK1 = 0x55555555555555555555555555555555 MSK2 = 0x33333333333333333333333333333333 MSK3 = 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f MSK4 = 0x00ff00ff00ff00ff00ff00ff00ff00ff MSK5 = 0x0000ffff0000ffff0000ffff0000ffff MSK6 = 0x00000000ffffffff00000000ffffffff MSK7 = 0x0000000000000000ffffffffffffffff def popcnt(x): x=(x & MSK1) + ((x>>1) & MSK1) x=(x & MSK2) + ((x>>2) & MSK2) x=(x & MSK3) + ((x>>4) & MSK3) x=(x & MSK4) + ((x>>8) & MSK4) x=(x & MSK5) + ((x>>16) & MSK5) x=(x & MSK6) + ((x>>32) & MSK6) x=(x & MSK7) + ((x>>64) & MSK7) return x n,m = map(int,input().split()) a = [] b = [] for _ in range(m): ai, bi = map(int,input().split()) a.append(ai-1) b.append(bi-1) cv = list(map(int,input().split())) c = 0 for i in range(n): if cv[i]: c += (1 << i) seen = set() val = dict() m1 = m // 2 m2 = m - m1 for bt in range((1 << m1)): l = 0 for i in range(m1): if (bt >> i) & 1: l ^= (1 << a[i]) l ^= (1 << b[i]) if l in seen: val[l] = min(val[l], popcnt(bt)) else: val[l] = popcnt(bt) seen.add(l) ans = 100000000 for bt in range(1 << m2): l = c for i in range(m2): if (bt >> i) & 1: l ^= (1 << a[m1+i]) l ^= (1 << b[m1+i]) if l in seen: ans = min(ans, val[l] + popcnt(bt)) if ans == 100000000: print(-1) else: print(ans)