結果

問題 No.2701 A cans -> B cans
ユーザー tentententen
提出日時 2024-04-11 16:17:56
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,368 bytes
コンパイル時間 2,978 ms
コンパイル使用メモリ 79,008 KB
実行使用メモリ 463,068 KB
最終ジャッジ日時 2024-04-11 16:18:10
合計ジャッジ時間 12,786 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
57,056 KB
testcase_01 AC 53 ms
50,280 KB
testcase_02 AC 56 ms
50,248 KB
testcase_03 AC 50 ms
50,176 KB
testcase_04 AC 50 ms
50,400 KB
testcase_05 AC 52 ms
50,408 KB
testcase_06 AC 73 ms
51,164 KB
testcase_07 AC 68 ms
50,900 KB
testcase_08 AC 83 ms
51,360 KB
testcase_09 AC 71 ms
50,828 KB
testcase_10 AC 70 ms
50,548 KB
testcase_11 AC 69 ms
50,804 KB
testcase_12 AC 89 ms
51,180 KB
testcase_13 AC 89 ms
51,072 KB
testcase_14 AC 69 ms
50,880 KB
testcase_15 AC 70 ms
50,872 KB
testcase_16 AC 82 ms
51,100 KB
testcase_17 AC 84 ms
51,108 KB
testcase_18 AC 71 ms
50,764 KB
testcase_19 AC 70 ms
50,428 KB
testcase_20 AC 71 ms
51,136 KB
testcase_21 AC 71 ms
51,020 KB
testcase_22 AC 69 ms
50,956 KB
testcase_23 AC 68 ms
50,984 KB
testcase_24 AC 87 ms
51,124 KB
testcase_25 AC 70 ms
50,892 KB
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
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 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
権限があれば一括ダウンロードができます

ソースコード

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 * 2];
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            long c = sc.nextInt();
            counts[i * 2] = a - b;
            values[i * 2] = b * c;
            counts[i * 2 + 1] = a;
            values[i * 2 + 1] = b * c;
        }
        dp = new long[n * 2][m + 1];
        for (long[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= m; i++) {
            sb.append(dfw(n * 2 - 1, i)).append("\n");
        }
        System.out.print(sb);
    }
    
    static long dfw(int idx, int v) {
        if (v < 0) {
            return Long.MIN_VALUE;
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][v] < 0) {
            if (idx % 2 == 0) {
                dp[idx][v] = Math.max(dfw(idx - 1, v), dfw(idx, v - counts[idx]) + values[idx]);
            } else {
                dp[idx][v] = Math.max(dfw(idx - 2, v), dfw(idx - 1, v - counts[idx]) + values[idx]);
            }
        }
        return dp[idx][v];
    }
}
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