結果
問題 | No.2236 Lights Out On Simple Graph |
ユーザー | tenten |
提出日時 | 2023-07-06 15:09:50 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,581 bytes |
コンパイル時間 | 2,811 ms |
コンパイル使用メモリ | 87,820 KB |
実行使用メモリ | 370,704 KB |
最終ジャッジ日時 | 2023-09-27 16:12:16 |
合計ジャッジ時間 | 72,518 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
49,324 KB |
testcase_01 | AC | 37 ms
49,376 KB |
testcase_02 | AC | 37 ms
49,400 KB |
testcase_03 | AC | 1,812 ms
258,772 KB |
testcase_04 | WA | - |
testcase_05 | AC | 40 ms
49,612 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 40 ms
49,864 KB |
testcase_09 | AC | 37 ms
49,468 KB |
testcase_10 | AC | 489 ms
88,452 KB |
testcase_11 | AC | 152 ms
57,536 KB |
testcase_12 | AC | 858 ms
105,960 KB |
testcase_13 | AC | 128 ms
58,256 KB |
testcase_14 | AC | 1,477 ms
173,240 KB |
testcase_15 | AC | 117 ms
57,788 KB |
testcase_16 | AC | 158 ms
62,728 KB |
testcase_17 | AC | 206 ms
69,700 KB |
testcase_18 | AC | 61 ms
48,992 KB |
testcase_19 | AC | 350 ms
75,888 KB |
testcase_20 | WA | - |
testcase_21 | AC | 311 ms
77,976 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 2,205 ms
272,708 KB |
testcase_25 | WA | - |
testcase_26 | AC | 2,434 ms
322,556 KB |
testcase_27 | AC | 1,020 ms
134,024 KB |
testcase_28 | AC | 1,750 ms
269,484 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 1,803 ms
221,728 KB |
testcase_36 | AC | 937 ms
198,604 KB |
testcase_37 | AC | 1,702 ms
274,476 KB |
testcase_38 | AC | 540 ms
84,564 KB |
testcase_39 | AC | 340 ms
78,720 KB |
testcase_40 | AC | 1,104 ms
118,868 KB |
testcase_41 | AC | 284 ms
75,432 KB |
testcase_42 | AC | 519 ms
85,784 KB |
testcase_43 | AC | 137 ms
58,180 KB |
testcase_44 | AC | 1,114 ms
187,196 KB |
testcase_45 | WA | - |
testcase_46 | AC | 2,773 ms
275,524 KB |
testcase_47 | WA | - |
testcase_48 | AC | 2,369 ms
266,764 KB |
testcase_49 | WA | - |
testcase_50 | AC | 96 ms
54,916 KB |
testcase_51 | AC | 674 ms
126,648 KB |
testcase_52 | AC | 120 ms
55,932 KB |
testcase_53 | AC | 41 ms
49,324 KB |
testcase_54 | AC | 1,810 ms
268,008 KB |
testcase_55 | AC | 570 ms
94,636 KB |
testcase_56 | AC | 403 ms
87,696 KB |
testcase_57 | AC | 637 ms
112,048 KB |
testcase_58 | AC | 561 ms
90,152 KB |
testcase_59 | AC | 616 ms
99,472 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); long[] evValue = new long[(m + 1) / 2]; long[] odValue = new long[m / 2]; for (int i = 0; i < m; i++) { if (i % 2 == 0) { evValue[i / 2] = (1L << (sc.nextInt() - 1)) + (1L << (sc.nextInt() - 1)); } else { odValue[i / 2] = (1L << (sc.nextInt() - 1)) + (1L << (sc.nextInt() - 1)); } } long[] evDp = new long[1 << evValue.length]; HashMap<Long, Integer> evCount = new HashMap<>(); for (int i = 0; i < (1 << evValue.length); i++) { int pop = getPop(i); for (int j = 0; j < evValue.length; j++) { if ((i & (1 << j)) == 0) { continue; } evDp[i] = evDp[i ^ (1 << j)] ^ evValue[j]; break; } evCount.put(evDp[i], Math.min(evCount.getOrDefault(evDp[i], Integer.MAX_VALUE), pop)); } long[] odDp = new long[1 << odValue.length]; HashMap<Long, Integer> odCount = new HashMap<>(); for (int i = 0; i < (1 << odValue.length); i++) { int pop = getPop(i); for (int j = 0; j < odValue.length; j++) { if ((i & (1 << j)) == 0) { continue; } odDp[i] = odDp[i ^ (1 << j)] ^ odValue[j]; break; } odCount.put(odDp[i], Math.min(odCount.getOrDefault(odDp[i], Integer.MAX_VALUE), pop)); } long base = 0; for (int i = 0; i < n; i++) { base += (sc.nextInt() << i); } int ans = Integer.MAX_VALUE / 2; for (long x : evCount.keySet()) { ans = Math.min(ans, evCount.get(x) + odCount.getOrDefault(x ^ base, Integer.MAX_VALUE / 2)); } if (ans >= Integer.MAX_VALUE / 2) { System.out.println(-1); } else { System.out.println(ans); } } static int getPop(int x) { int pop = 0; while (x > 0) { pop += x % 2; x >>= 1; } return pop; } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }