結果

問題 No.1037 exhausted
ユーザー tentententen
提出日時 2024-07-22 15:29:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 1,950 bytes
コンパイル時間 4,943 ms
コンパイル使用メモリ 78,376 KB
実行使用メモリ 79,620 KB
最終ジャッジ日時 2024-07-22 15:29:49
合計ジャッジ時間 7,495 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
36,984 KB
testcase_01 AC 50 ms
37,044 KB
testcase_02 AC 51 ms
36,908 KB
testcase_03 AC 51 ms
36,856 KB
testcase_04 AC 51 ms
36,752 KB
testcase_05 AC 51 ms
36,468 KB
testcase_06 AC 51 ms
36,760 KB
testcase_07 AC 52 ms
36,808 KB
testcase_08 AC 51 ms
36,956 KB
testcase_09 AC 51 ms
36,876 KB
testcase_10 AC 51 ms
37,028 KB
testcase_11 AC 50 ms
36,876 KB
testcase_12 AC 212 ms
79,620 KB
testcase_13 AC 201 ms
76,144 KB
testcase_14 AC 201 ms
79,416 KB
testcase_15 AC 197 ms
79,560 KB
testcase_16 AC 206 ms
76,804 KB
testcase_17 AC 206 ms
77,048 KB
testcase_18 AC 198 ms
76,384 KB
testcase_19 AC 202 ms
75,924 KB
testcase_20 AC 193 ms
79,148 KB
testcase_21 AC 197 ms
78,996 KB
testcase_22 AC 183 ms
76,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int volume = sc.nextInt();
        int length = sc.nextInt();
        int prev = 0;
        long[][] dp = new long[n + 1][volume + 1];
        for (int i = 1; i <= n; i++) {
            Arrays.fill(dp[i], Long.MAX_VALUE / 2);
            int x = sc.nextInt();
            int v = sc.nextInt();
            int cost = sc.nextInt();
            int dist = x - prev;
            for (int j = volume; j - dist >= 0; j--) {
                dp[i][j - dist] = dp[i - 1][j];
            }
            for (int j = volume; j >= 1; j--) {
                dp[i][j] = Math.min(dp[i][j], dp[i][Math.max(0, j - v)] + cost);
            }
            prev = x;
        }
        int current = length - prev;
        long ans = current <= volume ? dp[n][current] : Long.MAX_VALUE / 2;
        System.out.println(ans >= Long.MAX_VALUE / 2 ? -1 : ans);
    }
}
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();
        }
    }
    
}


0