結果
問題 | No.1457 ツブ消ししとるなHard |
ユーザー | 小野寺健 |
提出日時 | 2021-05-01 09:53:35 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 226 ms / 2,000 ms |
コード長 | 1,749 bytes |
コンパイル時間 | 4,054 ms |
コンパイル使用メモリ | 84,496 KB |
実行使用メモリ | 87,488 KB |
最終ジャッジ日時 | 2023-09-26 22:29:44 |
合計ジャッジ時間 | 8,604 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 128 ms
56,272 KB |
testcase_01 | AC | 128 ms
55,612 KB |
testcase_02 | AC | 128 ms
56,072 KB |
testcase_03 | AC | 126 ms
56,220 KB |
testcase_04 | AC | 212 ms
79,916 KB |
testcase_05 | AC | 226 ms
87,488 KB |
testcase_06 | AC | 213 ms
80,184 KB |
testcase_07 | AC | 130 ms
56,068 KB |
testcase_08 | AC | 127 ms
55,972 KB |
testcase_09 | AC | 163 ms
58,284 KB |
testcase_10 | AC | 150 ms
55,916 KB |
testcase_11 | AC | 131 ms
56,064 KB |
testcase_12 | AC | 172 ms
60,692 KB |
testcase_13 | AC | 162 ms
58,008 KB |
testcase_14 | AC | 133 ms
55,608 KB |
testcase_15 | AC | 165 ms
58,816 KB |
testcase_16 | AC | 195 ms
64,808 KB |
testcase_17 | AC | 128 ms
55,608 KB |
testcase_18 | AC | 128 ms
55,932 KB |
testcase_19 | AC | 198 ms
69,168 KB |
testcase_20 | AC | 126 ms
56,040 KB |
ソースコード
package yukicoder; import java.util.Scanner; import java.util.List; import java.util.ArrayList; import java.util.Collections; public class No1457 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int M = scan.nextInt(); int X = scan.nextInt(); int Y = scan.nextInt(); int Z = scan.nextInt(); List<Integer> A = new ArrayList<Integer>(); for (int i=0; i < N; i++) { A.add(scan.nextInt()); } scan.close(); Collections.sort(A); int remove = Collections.binarySearch(A, Y + 1); if (remove < 0) { remove = - remove - 1; } int remain = Collections.binarySearch(A, X); if (remain < 0) { remain = - remain - 1; } int remainN = N - remain; if (remainN > M) { System.out.println("Handicapped"); return; } int remainSum = A.subList(remain, N).stream().reduce(0, (a, b) -> a + b); List<Integer> B = A.subList(remove, remain); int min = remainN > 0 ? 0 : 1; int max = M - remainN; int n = remain - remove; if (n == 0) { if (remainSum == remainN * Z) { System.out.println(1); } else { System.out.println(0); } return; } int maxsum = Z * M; long[][][] dp = new long[n][max+1][maxsum+1]; dp[0][0][0] = 1; if (B.get(0) <= maxsum) { dp[0][1][B.get(0)] = 1; } for (int i=0; i < n-1; i++) { for (int j=0; j <= max; j++) { for (int k=0; k <= maxsum; k++) { dp[i+1][j][k] += dp[i][j][k]; if (j+1 <= max && k+B.get(i+1) <= maxsum) { dp[i+1][j+1][k+B.get(i+1)] += dp[i][j][k]; } } } } long cnt = 0; for (int j=min; j <= max; j++) { int k = Z*(j+remainN)-remainSum; if (k >= 0 && k <= maxsum) { cnt += dp[n-1][j][k]; } } System.out.println(cnt); } }