結果
問題 |
No.2236 Lights Out On Simple Graph
|
ユーザー |
![]() |
提出日時 | 2023-03-03 23:13:18 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 860 bytes |
コンパイル時間 | 194 ms |
コンパイル使用メモリ | 82,060 KB |
実行使用メモリ | 848,796 KB |
最終ジャッジ日時 | 2024-09-18 00:21:26 |
合計ジャッジ時間 | 6,286 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | MLE * 1 -- * 56 |
ソースコード
from collections import defaultdict def popcount(n): c=(n&0x5555555555555555)+((n>>1)&0x5555555555555555) c=(c&0x3333333333333333)+((c>>2)&0x3333333333333333) c=(c&0x0f0f0f0f0f0f0f0f)+((c>>4)&0x0f0f0f0f0f0f0f0f) c=(c&0x00ff00ff00ff00ff)+((c>>8)&0x00ff00ff00ff00ff) c=(c&0x0000ffff0000ffff)+((c>>16)&0x0000ffff0000ffff) c=(c&0x00000000ffffffff)+((c>>32)&0x00000000ffffffff) return c n, m = map(int,input().split()) a = [0] * m b = [0] * m for i in range(m): a[i], b[i] = map(int,input().split()) a[i] -= 1 b[i] -= 1 c = list(map(int,input().split())) v = 0 for i in range(n): v ^= c[i] << i r = defaultdict(lambda: 10 ** 9) r[v] = 0 for i in range(m): for w, c in list(r.items()): x = w ^ (1 << a[i]) ^ (1 << b[i]) if popcount(w) < popcount(x): continue if r[x] > c + 1: r[x] = c + 1 if r[0] == 10 ** 9: print(-1) else: print(r[0])