結果
問題 | No.1457 ツブ消ししとるなHard |
ユーザー | 小野寺健 |
提出日時 | 2021-05-01 09:25:42 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 239 ms / 2,000 ms |
コード長 | 1,773 bytes |
コンパイル時間 | 5,648 ms |
コンパイル使用メモリ | 87,432 KB |
実行使用メモリ | 87,056 KB |
最終ジャッジ日時 | 2023-09-26 21:50:59 |
合計ジャッジ時間 | 8,891 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 134 ms
55,952 KB |
testcase_01 | AC | 132 ms
56,080 KB |
testcase_02 | AC | 132 ms
56,152 KB |
testcase_03 | AC | 132 ms
55,892 KB |
testcase_04 | AC | 221 ms
80,232 KB |
testcase_05 | AC | 239 ms
87,056 KB |
testcase_06 | AC | 217 ms
80,208 KB |
testcase_07 | AC | 130 ms
55,680 KB |
testcase_08 | AC | 135 ms
55,584 KB |
testcase_09 | AC | 138 ms
56,236 KB |
testcase_10 | AC | 139 ms
56,192 KB |
testcase_11 | AC | 131 ms
56,040 KB |
testcase_12 | AC | 173 ms
60,600 KB |
testcase_13 | AC | 162 ms
58,508 KB |
testcase_14 | AC | 136 ms
55,872 KB |
testcase_15 | AC | 161 ms
58,196 KB |
testcase_16 | AC | 161 ms
58,356 KB |
testcase_17 | AC | 122 ms
56,008 KB |
testcase_18 | AC | 126 ms
55,552 KB |
testcase_19 | AC | 200 ms
71,392 KB |
testcase_20 | AC | 134 ms
56,012 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 = B.stream().mapToInt(Integer::intValue).sum(); int maxval = maxsum - Collections.max(B); long[][][] dp = new long[n][max+1][maxsum+1]; dp[0][0][0] = 1; 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 <= maxval; k++) { dp[i+1][j][k] += dp[i][j][k]; if (j+1 <= max) { 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); } }