結果
問題 | No.1345 Beautiful BINGO |
ユーザー | 小野寺健 |
提出日時 | 2021-05-28 10:06:04 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,789 ms / 2,000 ms |
コード長 | 3,128 bytes |
コンパイル時間 | 4,717 ms |
コンパイル使用メモリ | 85,160 KB |
実行使用メモリ | 56,340 KB |
最終ジャッジ日時 | 2024-11-07 01:04:10 |
合計ジャッジ時間 | 47,421 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 137 ms
41,352 KB |
testcase_01 | AC | 143 ms
41,720 KB |
testcase_02 | AC | 139 ms
41,700 KB |
testcase_03 | AC | 133 ms
41,360 KB |
testcase_04 | AC | 135 ms
41,584 KB |
testcase_05 | AC | 159 ms
41,968 KB |
testcase_06 | AC | 134 ms
41,296 KB |
testcase_07 | AC | 184 ms
42,840 KB |
testcase_08 | AC | 131 ms
41,356 KB |
testcase_09 | AC | 134 ms
41,368 KB |
testcase_10 | AC | 148 ms
41,544 KB |
testcase_11 | AC | 141 ms
40,728 KB |
testcase_12 | AC | 137 ms
41,540 KB |
testcase_13 | AC | 173 ms
42,708 KB |
testcase_14 | AC | 141 ms
41,628 KB |
testcase_15 | AC | 134 ms
41,284 KB |
testcase_16 | AC | 142 ms
41,480 KB |
testcase_17 | AC | 140 ms
41,276 KB |
testcase_18 | AC | 132 ms
41,540 KB |
testcase_19 | AC | 135 ms
41,388 KB |
testcase_20 | AC | 129 ms
41,264 KB |
testcase_21 | AC | 136 ms
41,588 KB |
testcase_22 | AC | 393 ms
47,236 KB |
testcase_23 | AC | 1,709 ms
56,340 KB |
testcase_24 | AC | 1,300 ms
52,508 KB |
testcase_25 | AC | 283 ms
46,364 KB |
testcase_26 | AC | 797 ms
52,108 KB |
testcase_27 | AC | 1,715 ms
51,956 KB |
testcase_28 | AC | 287 ms
46,156 KB |
testcase_29 | AC | 744 ms
51,312 KB |
testcase_30 | AC | 566 ms
51,356 KB |
testcase_31 | AC | 406 ms
48,836 KB |
testcase_32 | AC | 194 ms
44,480 KB |
testcase_33 | AC | 1,789 ms
55,684 KB |
testcase_34 | AC | 241 ms
45,876 KB |
testcase_35 | AC | 244 ms
45,888 KB |
testcase_36 | AC | 1,682 ms
55,164 KB |
testcase_37 | AC | 242 ms
46,108 KB |
testcase_38 | AC | 835 ms
53,160 KB |
testcase_39 | AC | 1,713 ms
52,260 KB |
testcase_40 | AC | 1,311 ms
52,604 KB |
testcase_41 | AC | 1,217 ms
51,804 KB |
testcase_42 | AC | 137 ms
41,512 KB |
testcase_43 | AC | 136 ms
41,444 KB |
testcase_44 | AC | 138 ms
41,312 KB |
testcase_45 | AC | 139 ms
41,432 KB |
testcase_46 | AC | 139 ms
41,252 KB |
testcase_47 | AC | 136 ms
41,368 KB |
testcase_48 | AC | 139 ms
41,576 KB |
testcase_49 | AC | 136 ms
41,684 KB |
testcase_50 | AC | 138 ms
41,648 KB |
testcase_51 | AC | 140 ms
41,820 KB |
testcase_52 | AC | 1,527 ms
51,376 KB |
testcase_53 | AC | 1,590 ms
55,440 KB |
testcase_54 | AC | 1,743 ms
55,428 KB |
testcase_55 | AC | 1,492 ms
51,092 KB |
testcase_56 | AC | 1,685 ms
55,164 KB |
testcase_57 | AC | 1,652 ms
55,208 KB |
testcase_58 | AC | 1,706 ms
55,388 KB |
testcase_59 | AC | 1,722 ms
55,716 KB |
testcase_60 | AC | 1,573 ms
55,240 KB |
testcase_61 | AC | 1,596 ms
55,624 KB |
testcase_62 | AC | 1,602 ms
52,712 KB |
ソースコード
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; import java.util.stream.Collectors; public class No1345 { public static class Combination { public static List<List<Integer>> make (List<Integer> candidate, int r) { if (candidate.size() < r || candidate.size() <= 0 || r <= 0) { List<List<Integer>> empty = new ArrayList<>(); empty.add(new ArrayList<>()); return empty; } List<List<Integer>> combination = new ArrayList<>(); for (int i = 0; i <= candidate.size() - r; i++) { Integer picked = candidate.get(i); List<Integer> rest = new ArrayList<>(candidate); rest.subList(0, i + 1).clear(); combination.addAll(make(rest, r - 1).stream().map(list -> { list.add(0, picked); return list; }).collect(Collectors.toList())); } return combination; } } private static class Row { public List<Integer> row; public List<Integer> diag; public int cnt; public int[] col; public int size; public Row(int n) { row = new ArrayList<Integer>(); diag = new ArrayList<Integer>(); cnt = 0; col = new int[n]; size = 0; } public void SetCol(int[][] A) { for (int i=0; i < col.length; i++) { for (int j : row) { if (!ContainDiag(j, i)) { col[i] += A[j][i]; } } } Arrays.sort(col); for (int i=0; i < col.length-1; i++) { col[i+1] += col[i]; } } public void SetDiag(int row, int col) { int i = (row << 16) + col; if (!diag.contains(i)) { diag.add(i); } } public boolean ContainDiag(int row, int col) { int i = (row << 16) + col; return diag.contains(i); } } public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int M = scan.nextInt(); int[] RowSum = new int[N]; int[][] A = new int[N][N]; for (int i=0; i < N; i++) { int sum = 0; for (int j=0; j < N; j++) { int a = scan.nextInt(); sum += a; A[i][j] = a; } RowSum[i] = sum; } scan.close(); int ans = Integer.MAX_VALUE; for (int i=0; i < 1 << (N+2); i++) { Row row = new Row(N); for (int j=0; j < N; j++) { if ((i & (1 << j)) != 0) { row.cnt += RowSum[j]; row.size++; } else { row.row.add(j); } } if ((i & (3 << N)) != 0) { for (int j = 0; j < N; j++) { if (row.row.contains(j)) { if ((i & (1 << N)) != 0) { row.cnt += A[j][j]; row.SetDiag(j, j); } if ((i & (1 << (N+1))) != 0) { if (!row.ContainDiag(j, N-1-j)) { row.cnt += A[j][N-1-j]; row.SetDiag(j, N-1-j); } } } } if ((i & (1 << N)) != 0) { row.size++; } if ((i & (1 << (N+1))) != 0) { row.size++; } } row.SetCol(A); if (row.size == M) { ans = Math.min(ans, row.cnt); } else if (row.size < M && M - row.size <= N) { ans = Math.min(ans, row.cnt + row.col[M-row.size-1]); } } System.out.println(ans); } }