結果
| 問題 | No.3014 岩井満足性問題 |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2025-01-28 09:50:55 |
| 言語 | Java (openjdk 23) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,194 bytes |
| 記録 | |
| コンパイル時間 | 2,800 ms |
| コンパイル使用メモリ | 82,484 KB |
| 実行使用メモリ | 744,904 KB |
| 最終ジャッジ日時 | 2025-01-28 09:51:18 |
| 合計ジャッジ時間 | 21,861 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 MLE * 1 |
| other | AC * 14 TLE * 3 MLE * 1 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
static int[] values;
static int[] beauties;
static List<Map<Integer, Map<Integer, Long>>> dp = new ArrayList<>();
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int d = sc.nextInt();
int k = sc.nextInt();
values = new int[n];
for (int i = 0; i < n; i++) {
values[i] = sc.nextInt();
}
beauties = new int[n];
for (int i = 0; i < n; i++) {
beauties[i] = sc.nextInt();
dp.add(new HashMap<>());
}
long ans = dfw(n - 1, d - 1, k);
System.out.println(ans <= Long.MIN_VALUE / 3 ? "No" : String.valueOf(ans));
}
static long dfw(int idx, int v, int w) {
if (v < 0) {
return w == 0 ? 0 : Long.MIN_VALUE / 2;
}
if (idx < v) {
return Long.MIN_VALUE / 2;
}
if (!dp.get(idx).containsKey(v)) {
dp.get(idx).put(v, new HashMap<>());
}
if (!dp.get(idx).get(v).containsKey(w)) {
dp.get(idx).get(v).put(w, Math.max(dfw(idx - 1, v, w), dfw(idx - 1, v - 1, Math.max(0, w - beauties[idx])) + values[idx]));
}
return dp.get(idx).get(v).get(w);
}
}
class Scanner {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
public Scanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
} catch (Exception e) {
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
try {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
return st.nextToken();
}
}
}
tenten