結果

問題 No.2701 A cans -> B cans
ユーザー tentententen
提出日時 2024-04-01 15:15:29
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,412 bytes
コンパイル時間 2,489 ms
コンパイル使用メモリ 85,532 KB
実行使用メモリ 56,420 KB
最終ジャッジ日時 2024-04-01 15:15:38
合計ジャッジ時間 9,291 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
54,624 KB
testcase_01 AC 71 ms
54,644 KB
testcase_02 AC 71 ms
54,884 KB
testcase_03 AC 105 ms
56,176 KB
testcase_04 AC 128 ms
56,060 KB
testcase_05 AC 101 ms
54,216 KB
testcase_06 AC 104 ms
56,288 KB
testcase_07 AC 106 ms
56,288 KB
testcase_08 AC 129 ms
56,172 KB
testcase_09 AC 105 ms
54,348 KB
testcase_10 AC 108 ms
56,304 KB
testcase_11 AC 107 ms
56,304 KB
testcase_12 AC 106 ms
56,308 KB
testcase_13 AC 103 ms
56,292 KB
testcase_14 AC 105 ms
56,288 KB
testcase_15 AC 106 ms
56,284 KB
testcase_16 AC 105 ms
56,296 KB
testcase_17 AC 105 ms
56,276 KB
testcase_18 AC 126 ms
56,180 KB
testcase_19 AC 103 ms
56,188 KB
testcase_20 AC 106 ms
56,420 KB
testcase_21 AC 105 ms
56,160 KB
testcase_22 AC 106 ms
56,288 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[][] counts;
    static long[] values;
    static long[][][] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        counts = new int[n][2];
        values = new long[n];
        dp = new long[n][m + 1][2];
        for (int i = 0; i < n; i++) {
            counts[i][0] = sc.nextInt();
            int b = sc.nextInt();
            counts[i][1] = counts[i][0] - b;
            values[i] = sc.nextInt() * (long)b;
            for (long[] arr : dp[i]) {
                Arrays.fill(arr, -1);
            }
        }
        String result = IntStream.rangeClosed(1, m).mapToObj(i -> String.valueOf(dfw(n - 1, i, 0)))
            .collect(Collectors.joining("\n"));
        System.out.println(result);
    }
    
    static long dfw(int idx, int v, int w) {
        if (v < 0) {
            return Long.MIN_VALUE / 2;
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][v][w] < 0) {
            if (w == 0) {
                dp[idx][v][w] = Math.max(dfw(idx - 1, v, 0), dfw(idx, v - counts[idx][w], 1) + values[idx]);
            } else {
                int current = v / counts[idx][1];
                dp[idx][v][w] = Math.max(dfw(idx - 1, v, 0), dfw(idx - 1, v % counts[idx][1], 0) + values[idx] * current);
            }
            
        }
        return dp[idx][v][w];
    }
}
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