結果
問題 | No.1560 majority x majority |
ユーザー | tenten |
提出日時 | 2021-06-28 13:27:20 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 657 ms / 2,000 ms |
コード長 | 2,291 bytes |
コンパイル時間 | 2,015 ms |
コンパイル使用メモリ | 73,996 KB |
実行使用メモリ | 78,340 KB |
最終ジャッジ日時 | 2023-09-07 18:23:24 |
合計ジャッジ時間 | 10,327 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 578 ms
78,252 KB |
testcase_01 | AC | 657 ms
78,340 KB |
testcase_02 | AC | 42 ms
49,408 KB |
testcase_03 | AC | 477 ms
70,784 KB |
testcase_04 | AC | 472 ms
68,428 KB |
testcase_05 | AC | 479 ms
67,892 KB |
testcase_06 | AC | 128 ms
55,244 KB |
testcase_07 | AC | 176 ms
55,536 KB |
testcase_08 | AC | 357 ms
60,688 KB |
testcase_09 | AC | 242 ms
59,180 KB |
testcase_10 | AC | 59 ms
50,744 KB |
testcase_11 | AC | 153 ms
53,376 KB |
testcase_12 | AC | 119 ms
52,580 KB |
testcase_13 | AC | 142 ms
53,540 KB |
testcase_14 | AC | 123 ms
52,428 KB |
testcase_15 | AC | 161 ms
55,428 KB |
testcase_16 | AC | 89 ms
51,532 KB |
testcase_17 | AC | 423 ms
61,152 KB |
testcase_18 | AC | 250 ms
55,736 KB |
testcase_19 | AC | 60 ms
50,392 KB |
testcase_20 | AC | 92 ms
51,532 KB |
testcase_21 | AC | 108 ms
52,180 KB |
testcase_22 | AC | 340 ms
56,448 KB |
testcase_23 | AC | 83 ms
51,884 KB |
testcase_24 | AC | 68 ms
50,248 KB |
testcase_25 | AC | 289 ms
56,708 KB |
testcase_26 | AC | 42 ms
49,364 KB |
testcase_27 | AC | 42 ms
49,276 KB |
testcase_28 | AC | 42 ms
49,420 KB |
testcase_29 | AC | 43 ms
49,420 KB |
testcase_30 | AC | 45 ms
49,268 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { static int n; static int m; static boolean[][] votes; static boolean[][] unables; static int[] dp; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); boolean[][] votes = new boolean[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { votes[i][j] = (sc.nextInt() == 1); } } boolean[][] unables = new boolean[1 << m][n]; for (int i = 0; i < (1 << m); i++) { for (int j = 0; j < m; j++) { if ((i & (1 << j)) != 0) { continue; } for (int k = 0; k < n; k++) { unables[i][k] |= !votes[k][j]; } } } int[] dp = new int[1 << m]; dp[0] = 1; for (int i = 1; i < (1 << m); i++) { for (int j = 0; j < m; j++) { if ((i & (1 << j)) == 0) { continue; } int agree = 0; int against = 0; for (int k = 0; k < n; k++) { if (unables[i][k]) { continue; } if (votes[k][j]) { agree++; } else { against++; } } if (agree >= against) { dp[i] += dp[i ^ (1 << j)]; } } } System.out.println(dp[(1 << m) - 1]); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }