結果

問題 No.2808 Concentration
ユーザー tenten
提出日時 2024-07-17 12:47:39
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 2,633 bytes
コンパイル時間 2,455 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 242,260 KB
最終ジャッジ日時 2024-07-17 12:47:55
合計ジャッジ時間 16,078 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other TLE * 1 -- * 56
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
static List<Map<Integer, Long>> dp = new ArrayList<>();
static List<Speech> speeches = new ArrayList<>();
static int wake;
static int sleep;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
wake = sc.nextInt();
sleep = sc.nextInt();
for (int i = 0; i < n; i++) {
Speech current = new Speech(sc.nextInt(), sc.nextInt(), sc.nextInt());
if (current.length() <= wake) {
speeches.add(current);
dp.add(new HashMap<>());
}
}
Collections.sort(speeches);
System.out.println(dfw(speeches.size() - 1, Integer.MAX_VALUE));
}
static long dfw(int idx, int v) {
if (idx < 0) {
return 0;
}
if (v < speeches.get(idx).end) {
return dfw(idx - 1, v);
}
v = Math.min(v, speeches.get(idx).end);
if (!dp.get(idx).containsKey(v)) {
dp.get(idx).put(v, Math.max(dfw(idx - 1, v), dfw(idx - 1, speeches.get(idx).start - sleep) + speeches.get(idx).value));
}
return dp.get(idx).get(v);
}
static class Speech implements Comparable<Speech> {
int start;
int end;
int value;
public Speech(int start, int end, int value) {
this.start = start;
this.end = end;
this.value = value;
}
public int compareTo(Speech another) {
return end - another.end;
}
public int length() {
return end - start;
}
}
}
class Scanner {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
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();
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0