結果

問題 No.1457 ツブ消ししとるなHard
ユーザー 小野寺健小野寺健
提出日時 2021-05-01 09:51:12
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,717 bytes
コンパイル時間 5,884 ms
コンパイル使用メモリ 84,796 KB
実行使用メモリ 86,904 KB
最終ジャッジ日時 2023-09-26 22:25:14
合計ジャッジ時間 8,396 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,924 KB
testcase_01 AC 123 ms
55,900 KB
testcase_02 AC 125 ms
55,856 KB
testcase_03 AC 124 ms
55,968 KB
testcase_04 AC 210 ms
80,264 KB
testcase_05 AC 225 ms
86,904 KB
testcase_06 AC 212 ms
80,324 KB
testcase_07 AC 125 ms
55,772 KB
testcase_08 AC 126 ms
55,460 KB
testcase_09 AC 161 ms
58,632 KB
testcase_10 AC 146 ms
55,852 KB
testcase_11 AC 129 ms
55,904 KB
testcase_12 AC 169 ms
60,856 KB
testcase_13 AC 162 ms
58,404 KB
testcase_14 AC 132 ms
55,820 KB
testcase_15 AC 163 ms
58,088 KB
testcase_16 AC 190 ms
65,260 KB
testcase_17 AC 126 ms
56,320 KB
testcase_18 AC 128 ms
55,840 KB
testcase_19 AC 195 ms
69,020 KB
testcase_20 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
		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);
	}

}
0