結果
問題 | No.2236 Lights Out On Simple Graph |
ユーザー | mkawa2 |
提出日時 | 2023-03-04 12:05:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,039 ms / 4,000 ms |
コード長 | 1,379 bytes |
コンパイル時間 | 212 ms |
コンパイル使用メモリ | 82,788 KB |
実行使用メモリ | 270,612 KB |
最終ジャッジ日時 | 2024-09-18 01:04:12 |
合計ジャッジ時間 | 28,933 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
54,016 KB |
testcase_01 | AC | 46 ms
54,016 KB |
testcase_02 | AC | 46 ms
53,504 KB |
testcase_03 | AC | 1,011 ms
263,736 KB |
testcase_04 | AC | 752 ms
261,688 KB |
testcase_05 | AC | 47 ms
54,016 KB |
testcase_06 | AC | 876 ms
263,220 KB |
testcase_07 | AC | 776 ms
267,984 KB |
testcase_08 | AC | 42 ms
53,888 KB |
testcase_09 | AC | 50 ms
53,888 KB |
testcase_10 | AC | 217 ms
141,568 KB |
testcase_11 | AC | 99 ms
74,624 KB |
testcase_12 | AC | 293 ms
154,112 KB |
testcase_13 | AC | 74 ms
77,440 KB |
testcase_14 | AC | 586 ms
194,864 KB |
testcase_15 | AC | 70 ms
74,240 KB |
testcase_16 | AC | 87 ms
84,848 KB |
testcase_17 | AC | 135 ms
108,672 KB |
testcase_18 | AC | 60 ms
65,792 KB |
testcase_19 | AC | 115 ms
103,808 KB |
testcase_20 | AC | 472 ms
186,680 KB |
testcase_21 | AC | 118 ms
103,936 KB |
testcase_22 | AC | 990 ms
263,228 KB |
testcase_23 | AC | 1,013 ms
263,444 KB |
testcase_24 | AC | 592 ms
194,568 KB |
testcase_25 | AC | 192 ms
139,264 KB |
testcase_26 | AC | 1,003 ms
263,432 KB |
testcase_27 | AC | 493 ms
186,680 KB |
testcase_28 | AC | 755 ms
261,816 KB |
testcase_29 | AC | 117 ms
103,808 KB |
testcase_30 | AC | 1,004 ms
263,596 KB |
testcase_31 | AC | 990 ms
263,228 KB |
testcase_32 | AC | 1,039 ms
263,092 KB |
testcase_33 | AC | 989 ms
263,604 KB |
testcase_34 | AC | 1,018 ms
263,476 KB |
testcase_35 | AC | 878 ms
263,796 KB |
testcase_36 | AC | 569 ms
224,896 KB |
testcase_37 | AC | 976 ms
263,704 KB |
testcase_38 | AC | 341 ms
152,604 KB |
testcase_39 | AC | 233 ms
107,776 KB |
testcase_40 | AC | 323 ms
140,288 KB |
testcase_41 | AC | 113 ms
95,104 KB |
testcase_42 | AC | 331 ms
149,520 KB |
testcase_43 | AC | 84 ms
77,056 KB |
testcase_44 | AC | 601 ms
175,460 KB |
testcase_45 | AC | 866 ms
263,768 KB |
testcase_46 | AC | 690 ms
217,464 KB |
testcase_47 | AC | 821 ms
270,612 KB |
testcase_48 | AC | 793 ms
225,716 KB |
testcase_49 | AC | 753 ms
267,588 KB |
testcase_50 | AC | 68 ms
68,608 KB |
testcase_51 | AC | 210 ms
138,880 KB |
testcase_52 | AC | 80 ms
73,088 KB |
testcase_53 | AC | 48 ms
54,400 KB |
testcase_54 | AC | 425 ms
145,664 KB |
testcase_55 | AC | 343 ms
131,840 KB |
testcase_56 | AC | 296 ms
131,200 KB |
testcase_57 | AC | 337 ms
131,968 KB |
testcase_58 | AC | 272 ms
118,144 KB |
testcase_59 | AC | 262 ms
121,856 KB |
ソースコード
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)