結果
問題 | No.1345 Beautiful BINGO |
ユーザー | 小野寺健 |
提出日時 | 2021-05-27 15:52:49 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,580 bytes |
コンパイル時間 | 4,094 ms |
コンパイル使用メモリ | 81,860 KB |
実行使用メモリ | 52,780 KB |
最終ジャッジ日時 | 2024-04-24 03:02:33 |
合計ジャッジ時間 | 15,392 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 140 ms
41,596 KB |
testcase_02 | WA | - |
testcase_03 | AC | 138 ms
41,428 KB |
testcase_04 | WA | - |
testcase_05 | AC | 180 ms
42,376 KB |
testcase_06 | AC | 121 ms
40,244 KB |
testcase_07 | AC | 345 ms
49,548 KB |
testcase_08 | AC | 132 ms
40,908 KB |
testcase_09 | AC | 126 ms
41,244 KB |
testcase_10 | AC | 142 ms
41,620 KB |
testcase_11 | AC | 174 ms
42,220 KB |
testcase_12 | AC | 136 ms
41,392 KB |
testcase_13 | AC | 355 ms
49,684 KB |
testcase_14 | AC | 144 ms
41,736 KB |
testcase_15 | AC | 121 ms
41,368 KB |
testcase_16 | AC | 152 ms
41,512 KB |
testcase_17 | WA | - |
testcase_18 | AC | 131 ms
41,172 KB |
testcase_19 | AC | 138 ms
41,352 KB |
testcase_20 | AC | 133 ms
41,472 KB |
testcase_21 | AC | 132 ms
41,600 KB |
testcase_22 | AC | 178 ms
42,812 KB |
testcase_23 | AC | 284 ms
52,780 KB |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
testcase_60 | -- | - |
testcase_61 | -- | - |
testcase_62 | -- | - |
ソースコード
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Stack; import java.util.Scanner; public class No1345 { private static List<List<Integer>> combination(List list, int count) { List ret = new ArrayList<List<Integer>>(); for (int i=0; i < list.size(); i++) { if (i + count > list.size()) { break; } Stack stack = new Stack<Integer>(); stack.push(list.get(i)); _combination(ret, list, stack, i+1, count); } return ret; } private static void _combination(List ret, List list, Stack stack, int index, int count) { for (int i=index; i < list.size(); i++) { stack.push(list.get(i)); if (stack.size() == count) { ret.add(Arrays.asList(stack.toArray())); stack.pop(); continue; } _combination(ret, list, stack, i+1, count); stack.pop(); } } private static class Row { public List<Integer> row; public int cnt; public Row() { row = new ArrayList<Integer>(); cnt = 0; } } 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; } Row[] RowBlt = new Row[1<<N]; for (int i=0; i < 1 << N; i++) { Row row = new Row(); for (int j=0; j < N; j++) { if ((i & (1 << j)) != 0) { row.row.add(j); row.cnt += RowSum[j]; } } RowBlt[i] = row; } List<Integer> Range = new ArrayList<Integer>(); for (int i=0; i < N+2; i++) { Range.add(i); } int ans = Integer.MAX_VALUE; for (Row row : RowBlt) { if (row.row.size() > M) { continue; } else if (row.row.size() == M) { ans = Math.min(ans, row.cnt); } else { for (List<Integer> comb : combination(Range, M-row.row.size())) { int n = 0; for (int c : comb) { if (c == N) { for (int i=0; i < N; i++) { if (!row.row.contains(i) && !comb.contains(i)) { n += A[i][i]; } } } else if (c == N+1) { for (int i=0; i < N; i++) { if (!row.row.contains(i) && !comb.contains(N-1-i) && !(comb.contains(N) && i == N-1-i)) { n += A[i][N-1-i]; } } } else { for (int i=0; i < N; i++) { if (!row.row.contains(i)) { n += A[i][c]; } } } } ans = Math.min(ans, row.cnt + n); } } } System.out.println(ans); } }