結果
問題 | No.1560 majority x majority |
ユーザー | tenten |
提出日時 | 2023-02-02 15:37:09 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,258 bytes |
コンパイル時間 | 2,942 ms |
コンパイル使用メモリ | 95,864 KB |
実行使用メモリ | 69,380 KB |
最終ジャッジ日時 | 2024-07-02 04:18:54 |
合計ジャッジ時間 | 11,585 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 688 ms
57,112 KB |
testcase_01 | AC | 612 ms
53,272 KB |
testcase_02 | AC | 53 ms
36,956 KB |
testcase_03 | AC | 167 ms
42,472 KB |
testcase_04 | WA | - |
testcase_05 | AC | 1,486 ms
69,380 KB |
testcase_06 | AC | 88 ms
38,660 KB |
testcase_07 | AC | 136 ms
39,816 KB |
testcase_08 | AC | 156 ms
41,920 KB |
testcase_09 | AC | 122 ms
39,180 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 130 ms
39,596 KB |
testcase_14 | AC | 130 ms
39,756 KB |
testcase_15 | AC | 185 ms
42,068 KB |
testcase_16 | AC | 115 ms
39,344 KB |
testcase_17 | AC | 356 ms
48,320 KB |
testcase_18 | AC | 255 ms
45,180 KB |
testcase_19 | AC | 69 ms
38,020 KB |
testcase_20 | AC | 95 ms
38,832 KB |
testcase_21 | AC | 121 ms
39,224 KB |
testcase_22 | AC | 335 ms
46,920 KB |
testcase_23 | AC | 101 ms
38,628 KB |
testcase_24 | AC | 83 ms
38,024 KB |
testcase_25 | AC | 306 ms
47,264 KB |
testcase_26 | AC | 55 ms
37,080 KB |
testcase_27 | AC | 53 ms
36,768 KB |
testcase_28 | AC | 53 ms
36,696 KB |
testcase_29 | AC | 53 ms
36,964 KB |
testcase_30 | AC | 59 ms
36,580 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static int m; static Judge[] judges; static HashMap<Judge, HashMap<Integer, Integer>> dp = new HashMap<>(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); m = sc.nextInt(); Judge.size = n; judges = new Judge[m]; for (int i = 0; i < m; i++) { judges[i] = new Judge(); } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (sc.nextInt() == 1) { judges[j].add(i); } } } for (int i = 0; i < m; i++) { judges[i].makePop(); } Judge all = new Judge(); for (int i = 0; i < n; i++) { all.add(i); } System.out.println(dfw(all, (1 << m) - 1)); } static int dfw(Judge x, int mask) { if (mask == 0) { return 1; } if (!dp.containsKey(x)) { dp.put(x, new HashMap<>()); } if (!dp.get(x).containsKey(mask)) { int ans = 0; for (int i = 0; i < m; i++) { if ((mask & (1 << i)) == 0) { continue; } Judge next = judges[i].and(x); if (x.pop <= next.pop * 2) { ans += dfw(next, mask ^ (1 << i)); } } dp.get(x).put(mask, ans); } return dp.get(x).get(mask); } static class Judge { static int size; int length; long[] data; int pop; public Judge() { length = (size + 60 - 1) / 60; data = new long[length]; } public Judge(int length, long[] data) { this.length = length; this.data = data; } public void add(int x) { data[x / 60] |= (1L << (x % 60)); } public void makePop() { for (long x : data) { long y = x; while (y > 0) { if (y % 2 == 1) { pop++; } y >>= 1; } } } public Judge and(Judge x) { long[] next = new long[length]; for (int i = 0; i < length; i++) { next[i] = (data[i] & x.data[i]); } Judge ans = new Judge(length, next); ans.makePop(); return ans; } public int hashCode() { return pop; } public boolean equals(Object o) { Judge x = (Judge)o; for (int i = 0; i < length; i++) { if (data[i] != x.data[i]) { return false; } } return true; } } } 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(); } }