結果
| 問題 |
No.2236 Lights Out On Simple Graph
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2023-03-06 15:58:00 |
| 言語 | Java (openjdk 23) |
| 結果 |
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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 8 WA * 49 |
ソースコード
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();
}
}
tenten