結果

問題 No.2232 Miser's Gift
ユーザー tentententen
提出日時 2023-03-06 10:54:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 515 ms / 2,000 ms
コード長 2,403 bytes
コンパイル時間 4,126 ms
コンパイル使用メモリ 91,928 KB
実行使用メモリ 110,328 KB
最終ジャッジ日時 2023-10-18 05:08:05
合計ジャッジ時間 21,552 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
52,548 KB
testcase_01 AC 55 ms
52,580 KB
testcase_02 AC 56 ms
52,548 KB
testcase_03 AC 353 ms
93,400 KB
testcase_04 AC 334 ms
95,612 KB
testcase_05 AC 133 ms
59,640 KB
testcase_06 AC 55 ms
53,628 KB
testcase_07 AC 142 ms
58,148 KB
testcase_08 AC 398 ms
110,208 KB
testcase_09 AC 399 ms
110,260 KB
testcase_10 AC 392 ms
110,148 KB
testcase_11 AC 396 ms
110,260 KB
testcase_12 AC 395 ms
110,188 KB
testcase_13 AC 362 ms
93,576 KB
testcase_14 AC 362 ms
93,504 KB
testcase_15 AC 363 ms
93,564 KB
testcase_16 AC 368 ms
93,592 KB
testcase_17 AC 362 ms
93,572 KB
testcase_18 AC 358 ms
93,488 KB
testcase_19 AC 354 ms
93,020 KB
testcase_20 AC 341 ms
93,016 KB
testcase_21 AC 350 ms
93,008 KB
testcase_22 AC 346 ms
93,008 KB
testcase_23 AC 515 ms
110,272 KB
testcase_24 AC 493 ms
110,196 KB
testcase_25 AC 500 ms
110,328 KB
testcase_26 AC 497 ms
110,200 KB
testcase_27 AC 499 ms
110,152 KB
testcase_28 AC 440 ms
110,184 KB
testcase_29 AC 443 ms
110,204 KB
testcase_30 AC 432 ms
110,176 KB
testcase_31 AC 440 ms
110,260 KB
testcase_32 AC 453 ms
110,164 KB
testcase_33 AC 366 ms
95,504 KB
testcase_34 AC 366 ms
95,508 KB
testcase_35 AC 364 ms
93,600 KB
testcase_36 AC 359 ms
93,600 KB
testcase_37 AC 365 ms
93,600 KB
testcase_38 AC 80 ms
54,236 KB
testcase_39 AC 81 ms
53,944 KB
testcase_40 AC 81 ms
54,504 KB
testcase_41 AC 82 ms
54,476 KB
testcase_42 AC 84 ms
54,732 KB
testcase_43 AC 84 ms
54,772 KB
testcase_44 AC 83 ms
53,920 KB
testcase_45 AC 82 ms
54,468 KB
testcase_46 AC 82 ms
53,920 KB
testcase_47 AC 81 ms
54,600 KB
testcase_48 AC 58 ms
53,640 KB
testcase_49 AC 58 ms
53,640 KB
testcase_50 AC 57 ms
53,644 KB
testcase_51 AC 58 ms
53,640 KB
testcase_52 AC 57 ms
53,640 KB
testcase_53 AC 59 ms
53,648 KB
testcase_54 AC 60 ms
53,640 KB
testcase_55 AC 60 ms
52,552 KB
testcase_56 AC 59 ms
52,528 KB
testcase_57 AC 59 ms
53,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[][] dp;
    static int[] weights;
    static int[] values;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int w = sc.nextInt();
        weights = new int[n];
        values = new int[n];
        for (int i = 0; i < n; i++) {
            weights[i] = sc.nextInt();
            values[i] = sc.nextInt();
        }
        dp = new int[n][w + 1];
        for (int[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        int base = dfw(n - 1, w);
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= w; i++) {
            sb.append(base - dfw(n - 1, w - i) + 1).append("\n");
        }
        System.out.print(sb);
    }
    
    static int dfw(int idx, int v) {
        if (v < 0) {
            return Integer.MIN_VALUE;
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][v] < 0) {
            dp[idx][v] = Math.max(dfw(idx - 1, v), dfw(idx - 1, v - weights[idx]) + values[idx]);
        }
        return dp[idx][v];
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0