結果
| 問題 | No.1560 majority x majority |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-06-28 13:27:20 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 738 ms / 2,000 ms |
| コード長 | 2,291 bytes |
| 記録 | |
| コンパイル時間 | 3,185 ms |
| コンパイル使用メモリ | 77,588 KB |
| 実行使用メモリ | 79,584 KB |
| 最終ジャッジ日時 | 2024-06-25 12:09:36 |
| 合計ジャッジ時間 | 12,094 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 26 |
ソースコード
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();
}
}
tenten