結果
問題 | No.412 花火大会 |
ユーザー | htensai |
提出日時 | 2020-01-09 10:16:57 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 50 ms / 2,000 ms |
コード長 | 4,270 bytes |
コンパイル時間 | 2,523 ms |
コンパイル使用メモリ | 79,876 KB |
実行使用メモリ | 37,340 KB |
最終ジャッジ日時 | 2024-11-23 03:43:18 |
合計ジャッジ時間 | 3,970 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
37,332 KB |
testcase_01 | AC | 45 ms
37,076 KB |
testcase_02 | AC | 45 ms
37,080 KB |
testcase_03 | AC | 45 ms
37,164 KB |
testcase_04 | AC | 45 ms
36,808 KB |
testcase_05 | AC | 44 ms
36,936 KB |
testcase_06 | AC | 46 ms
36,804 KB |
testcase_07 | AC | 44 ms
37,104 KB |
testcase_08 | AC | 45 ms
37,180 KB |
testcase_09 | AC | 46 ms
37,192 KB |
testcase_10 | AC | 46 ms
37,308 KB |
testcase_11 | AC | 47 ms
36,940 KB |
testcase_12 | AC | 45 ms
37,036 KB |
testcase_13 | AC | 46 ms
37,328 KB |
testcase_14 | AC | 49 ms
37,340 KB |
testcase_15 | AC | 47 ms
37,332 KB |
testcase_16 | AC | 45 ms
36,980 KB |
testcase_17 | AC | 47 ms
37,332 KB |
testcase_18 | AC | 46 ms
37,308 KB |
testcase_19 | AC | 45 ms
36,948 KB |
testcase_20 | AC | 50 ms
36,804 KB |
testcase_21 | AC | 48 ms
36,804 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { static int[] families; static int[] sheets; static int[][] dp; //idx, 1, 2, 3 public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 3); families = new int[3]; for (int i = 0; i < 3; i++) { families[i] = Integer.parseInt(first[i]); } Arrays.sort(families); int n = Integer.parseInt(br.readLine()); sheets = new int[n + 1]; String[] line = br.readLine().split(" ", n); for (int i = 0; i < n; i++) { sheets[i + 1] = Integer.parseInt(line[i]); } Arrays.sort(sheets); dp = new int[n + 1][3 * 16 + 3 * 4 + 3 + 1]; for (int i = 0; i <= n; i++) { Arrays.fill(dp[i], -1); } System.out.print(dfw(n, 0)); } static int dfw(int idx, int value) { if (idx <= 0) { return 0; } if (dp[idx][value] != -1) { return dp[idx][value]; } int s = value / 16; int m = (value % 16) / 4; int l = value % 4; dp[idx][value] = dfw(idx - 1, value); if (sheets[idx] >= families[0]) { s = Math.min(s + 1, 3); } if (sheets[idx] >= families[1]) { m = Math.min(m + 1, 3); } if (sheets[idx] >= families[2]) { l = Math.min(l + 1, 3); } int next = s * 16 + m * 4 + l; if (s >= 3 && m >= 2 && l >= 1) { dp[idx][value] += (int)(Math.pow(2, idx - 1)); } else { dp[idx][value] += dfw(idx - 1, next); } return dp[idx][value]; } static class Bridge { int left; int right; public Bridge (String arg) { String[] arr = arg.split(" ", 2); left = Integer.parseInt(arr[0]) - 1; right = Integer.parseInt(arr[1]) - 1; } public int hashCode() { return left + right; } public boolean equals(Object o) { Bridge b = (Bridge)o; return b.left == left && b.right == right; } } static class UnionFindTree { int[] parents; HashMap<Integer, HashSet<Integer>> map = new HashMap<>(); HashSet<Integer> nothing = new HashSet<>(); public UnionFindTree(int size) { parents = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; } } public int find(int x) { if (parents[x] == x) { return x; } else { return parents[x] = find(parents[x]); } } public void unite(int x, int y) { int xx = find(x); int yy = find(y); if (xx == yy) { return; } int small = Math.min(xx, yy); int large = Math.max(xx, yy); parents[large] = small; } public void unite(Bridge b) { unite(b.left, b.right); } public HashSet<Integer> uniteNext(int x, int y) { int xx = find(x); int yy = find(y); if (xx == yy) { return nothing; } int small = Math.min(xx, yy); int large = Math.max(xx, yy); parents[large] = small; if (small == 0) { return map.get(large); } else { map.get(small).addAll(map.get(large)); return nothing; } } public HashSet<Integer> uniteNext(Bridge b) { return uniteNext(b.left, b.right); } public HashSet<Integer> prepare() { for (int i = 0; i < parents.length; i++) { int x = find(i); if (!map.containsKey(x)) { map.put(x, new HashSet<Integer>()); } map.get(x).add(i); } return map.get(0); } } }