結果
問題 | No.1345 Beautiful BINGO |
ユーザー | 小野寺健 |
提出日時 | 2021-05-28 09:51:41 |
言語 | Java (openjdk 23) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,498 bytes |
コンパイル時間 | 4,794 ms |
コンパイル使用メモリ | 84,624 KB |
実行使用メモリ | 220,796 KB |
最終ジャッジ日時 | 2024-11-07 00:57:29 |
合計ジャッジ時間 | 52,572 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 136 ms
41,572 KB |
testcase_01 | AC | 134 ms
41,408 KB |
testcase_02 | AC | 138 ms
41,496 KB |
testcase_03 | AC | 124 ms
40,280 KB |
testcase_04 | AC | 134 ms
41,240 KB |
testcase_05 | AC | 141 ms
40,416 KB |
testcase_06 | AC | 135 ms
41,468 KB |
testcase_07 | AC | 184 ms
42,468 KB |
testcase_08 | AC | 118 ms
40,112 KB |
testcase_09 | AC | 136 ms
41,532 KB |
testcase_10 | AC | 141 ms
41,476 KB |
testcase_11 | AC | 140 ms
41,444 KB |
testcase_12 | AC | 135 ms
41,308 KB |
testcase_13 | AC | 182 ms
42,504 KB |
testcase_14 | AC | 142 ms
41,572 KB |
testcase_15 | AC | 134 ms
41,548 KB |
testcase_16 | AC | 144 ms
41,404 KB |
testcase_17 | AC | 141 ms
41,244 KB |
testcase_18 | AC | 135 ms
41,608 KB |
testcase_19 | AC | 141 ms
41,440 KB |
testcase_20 | AC | 138 ms
41,672 KB |
testcase_21 | AC | 139 ms
41,508 KB |
testcase_22 | AC | 352 ms
51,472 KB |
testcase_23 | AC | 1,631 ms
57,288 KB |
testcase_24 | AC | 1,254 ms
54,432 KB |
testcase_25 | AC | 282 ms
48,204 KB |
testcase_26 | AC | 1,025 ms
88,620 KB |
testcase_27 | TLE | - |
testcase_28 | AC | 291 ms
45,920 KB |
testcase_29 | AC | 965 ms
87,484 KB |
testcase_30 | AC | 471 ms
52,376 KB |
testcase_31 | AC | 367 ms
47,892 KB |
testcase_32 | AC | 199 ms
44,092 KB |
testcase_33 | TLE | - |
testcase_34 | AC | 233 ms
45,888 KB |
testcase_35 | AC | 228 ms
45,752 KB |
testcase_36 | AC | 1,617 ms
69,056 KB |
testcase_37 | AC | 236 ms
45,828 KB |
testcase_38 | AC | 980 ms
85,532 KB |
testcase_39 | TLE | - |
testcase_40 | AC | 1,630 ms
133,072 KB |
testcase_41 | AC | 929 ms
72,008 KB |
testcase_42 | AC | 134 ms
41,288 KB |
testcase_43 | AC | 133 ms
41,732 KB |
testcase_44 | AC | 138 ms
41,380 KB |
testcase_45 | AC | 140 ms
41,068 KB |
testcase_46 | AC | 132 ms
41,288 KB |
testcase_47 | AC | 132 ms
41,320 KB |
testcase_48 | AC | 135 ms
41,192 KB |
testcase_49 | AC | 134 ms
41,468 KB |
testcase_50 | AC | 137 ms
41,272 KB |
testcase_51 | AC | 142 ms
41,724 KB |
testcase_52 | AC | 1,550 ms
53,756 KB |
testcase_53 | TLE | - |
testcase_54 | AC | 1,738 ms
73,428 KB |
testcase_55 | AC | 1,896 ms
124,924 KB |
testcase_56 | AC | 1,544 ms
55,276 KB |
testcase_57 | TLE | - |
testcase_58 | TLE | - |
testcase_59 | TLE | - |
testcase_60 | AC | 1,721 ms
89,208 KB |
testcase_61 | TLE | - |
testcase_62 | AC | 1,518 ms
54,944 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 Row(Row r) { row = r.row; diag = new ArrayList<Integer>(); cnt = r.cnt; col = new int[r.col.length]; size = r.size; } 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); } 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; List<Row> RowBlt = new ArrayList<Row>(); 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); } if (row.size < M && M - row.size <= N) { RowBlt.add(row); } } List<Integer> Range = new ArrayList<Integer>(); for (int i=0; i < N; i++) { Range.add(i); } for (Row row : RowBlt) { if (row.cnt >= ans) { continue; } int n = 0; for (int i=0; i < M-row.size; i++) { n += row.col[i]; } ans = Math.min(ans, row.cnt + n); } System.out.println(ans); } }