結果
問題 | No.1457 ツブ消ししとるなHard |
ユーザー | 小野寺健 |
提出日時 | 2021-05-01 08:59:44 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,741 bytes |
コンパイル時間 | 4,126 ms |
コンパイル使用メモリ | 87,980 KB |
実行使用メモリ | 87,524 KB |
最終ジャッジ日時 | 2023-09-26 18:38:21 |
合計ジャッジ時間 | 8,966 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 132 ms
56,060 KB |
testcase_01 | AC | 124 ms
55,596 KB |
testcase_02 | AC | 130 ms
56,252 KB |
testcase_03 | AC | 126 ms
55,636 KB |
testcase_04 | AC | 203 ms
80,616 KB |
testcase_05 | AC | 215 ms
87,524 KB |
testcase_06 | AC | 207 ms
80,060 KB |
testcase_07 | AC | 135 ms
57,552 KB |
testcase_08 | AC | 131 ms
55,932 KB |
testcase_09 | AC | 139 ms
55,564 KB |
testcase_10 | AC | 138 ms
56,148 KB |
testcase_11 | AC | 132 ms
55,968 KB |
testcase_12 | AC | 176 ms
61,264 KB |
testcase_13 | AC | 167 ms
58,692 KB |
testcase_14 | WA | - |
testcase_15 | AC | 171 ms
58,540 KB |
testcase_16 | AC | 170 ms
58,564 KB |
testcase_17 | AC | 129 ms
55,584 KB |
testcase_18 | AC | 132 ms
56,028 KB |
testcase_19 | AC | 193 ms
71,720 KB |
testcase_20 | AC | 131 ms
56,028 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]; 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); } }