結果
問題 | No.2236 Lights Out On Simple Graph |
ユーザー | tenten |
提出日時 | 2023-03-06 15:58:00 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,139 bytes |
コンパイル時間 | 2,201 ms |
コンパイル使用メモリ | 89,492 KB |
実行使用メモリ | 207,968 KB |
最終ジャッジ日時 | 2024-09-18 01:51:21 |
合計ジャッジ時間 | 35,690 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 51 ms
36,916 KB |
testcase_02 | WA | - |
testcase_03 | AC | 1,405 ms
186,940 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 49 ms
37,184 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 290 ms
67,804 KB |
testcase_41 | AC | 130 ms
48,020 KB |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | AC | 1,357 ms
132,124 KB |
testcase_47 | WA | - |
testcase_48 | AC | 1,583 ms
172,132 KB |
testcase_49 | AC | 815 ms
93,020 KB |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | AC | 48 ms
37,184 KB |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
ソースコード
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[] front = new long[m / 2]; long[] rear = new long[m - m / 2]; for (int i = 0; i < m / 2; i++) { front[i] = (1L << (sc.nextInt() - 1)) + (1L << (sc.nextInt() - 1)); } for (int i = 0; i < m - m / 2; i++) { rear[i] = (1L << (sc.nextInt() - 1)) + (1L << (sc.nextInt() - 1)); } long base = 0; for (int i = 0; i < n; i++) { if (sc.nextInt() == 1) { base += (1L << i); } } long[] dp1 = new long[1 <<(m / 2)]; HashMap<Long, Integer> counts1 = new HashMap<>(); counts1.put(base, 0); dp1[0] = base; for (int i = 1; i < (1 << (m / 2)); i++) { for (int j = 0; j < m / 2; j++) { if ((i & (1 << j)) == 0) { continue; } dp1[i] = dp1[i ^ (1 << j)] ^ front[j]; counts1.put(dp1[i], Math.min(counts1.getOrDefault(dp1[i], m), getPop(i))); break; } } int ans = Integer.MAX_VALUE; long[] dp2 = new long[1 <<(m - m / 2)]; for (int i = 0; i < (1 << (m - m / 2)); i++) { for (int j = 0; j < m - m / 2; j++) { if ((i & (1 << j)) == 0) { continue; } break; } } if (ans > m) { System.out.println(-1); } else { System.out.println(ans); } } static int getPop(long x) { long pop = 0; while (x > 0) { pop += x % 2; x >>= 1; } return (int)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(); } }