結果
| 問題 | No.1457 ツブ消ししとるなHard |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-04-13 15:41:46 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 88 ms / 2,000 ms |
| コード長 | 2,185 bytes |
| 記録 | |
| コンパイル時間 | 2,327 ms |
| コンパイル使用メモリ | 78,152 KB |
| 実行使用メモリ | 38,992 KB |
| 最終ジャッジ日時 | 2024-06-29 20:36:30 |
| 合計ジャッジ時間 | 4,365 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int m = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
int z = sc.nextInt();
ArrayList<Integer> list = new ArrayList<>();
int count = 0;
int total = 0;
for (int i = 0; i < n; i++) {
int a = sc.nextInt();
if (a >= x) {
count++;
total += a;
} else if (a > y) {
list.add(a);
}
}
if (count == m) {
if (m * z == total) {
System.out.println(1);
} else {
System.out.println(0);
}
return;
} else if (count > m) {
System.out.println("Handicapped");
return;
}
m -= count;
long[][] dp = new long[m + 1][list.size() * 50 + 1];
dp[0][0] = 1;
for (int i = 0; i < list.size(); i++) {
int a = list.get(i);
for (int j = Math.min(i, m - 1); j >= 0 ; j--) {
for (int k = j * 50; k >= 0; k--) {
dp[j + 1][k + a] += dp[j][k];
}
}
}
long ans = 0;
for (int i = 1; i <= m; i++) {
if ((i + count) * z - total >= 0 && (i + count) * z - total < dp[i].length) {
ans += dp[i][(i + count) * z - total];
}
}
System.out.println(ans);
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten