結果

問題 No.2232 Miser's Gift
ユーザー AsahiAsahi
提出日時 2023-03-03 23:05:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 529 ms / 2,000 ms
コード長 6,403 bytes
コンパイル時間 5,347 ms
コンパイル使用メモリ 86,768 KB
実行使用メモリ 223,972 KB
最終ジャッジ日時 2023-10-18 03:25:41
合計ジャッジ時間 25,514 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
57,596 KB
testcase_01 AC 129 ms
57,656 KB
testcase_02 AC 128 ms
57,544 KB
testcase_03 AC 464 ms
218,632 KB
testcase_04 AC 443 ms
219,672 KB
testcase_05 AC 234 ms
73,776 KB
testcase_06 AC 128 ms
57,536 KB
testcase_07 AC 289 ms
66,464 KB
testcase_08 AC 456 ms
220,056 KB
testcase_09 AC 452 ms
221,988 KB
testcase_10 AC 444 ms
222,016 KB
testcase_11 AC 447 ms
222,012 KB
testcase_12 AC 453 ms
221,992 KB
testcase_13 AC 479 ms
220,996 KB
testcase_14 AC 479 ms
221,220 KB
testcase_15 AC 479 ms
220,968 KB
testcase_16 AC 484 ms
220,956 KB
testcase_17 AC 484 ms
220,996 KB
testcase_18 AC 481 ms
221,236 KB
testcase_19 AC 440 ms
220,872 KB
testcase_20 AC 446 ms
220,920 KB
testcase_21 AC 445 ms
220,760 KB
testcase_22 AC 439 ms
220,768 KB
testcase_23 AC 529 ms
223,972 KB
testcase_24 AC 450 ms
222,004 KB
testcase_25 AC 448 ms
221,992 KB
testcase_26 AC 451 ms
222,000 KB
testcase_27 AC 443 ms
221,988 KB
testcase_28 AC 448 ms
222,104 KB
testcase_29 AC 453 ms
221,996 KB
testcase_30 AC 450 ms
222,104 KB
testcase_31 AC 448 ms
222,000 KB
testcase_32 AC 451 ms
222,048 KB
testcase_33 AC 490 ms
221,480 KB
testcase_34 AC 494 ms
221,464 KB
testcase_35 AC 493 ms
221,484 KB
testcase_36 AC 470 ms
220,952 KB
testcase_37 AC 499 ms
221,444 KB
testcase_38 AC 159 ms
59,724 KB
testcase_39 AC 156 ms
59,360 KB
testcase_40 AC 161 ms
59,700 KB
testcase_41 AC 161 ms
59,692 KB
testcase_42 AC 156 ms
59,352 KB
testcase_43 AC 161 ms
59,812 KB
testcase_44 AC 159 ms
59,712 KB
testcase_45 AC 157 ms
59,700 KB
testcase_46 AC 163 ms
59,372 KB
testcase_47 AC 156 ms
59,876 KB
testcase_48 AC 136 ms
57,672 KB
testcase_49 AC 135 ms
57,300 KB
testcase_50 AC 135 ms
57,384 KB
testcase_51 AC 139 ms
57,316 KB
testcase_52 AC 143 ms
55,772 KB
testcase_53 AC 136 ms
57,684 KB
testcase_54 AC 139 ms
57,688 KB
testcase_55 AC 138 ms
57,620 KB
testcase_56 AC 136 ms
57,320 KB
testcase_57 AC 136 ms
57,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;
import java.util.regex.Pattern;

class Main{


    static void solve(){

        int N = ni(), W = ni();
        long [][] dp = new long[N+1][W+1];
        long [][] ct = new long[N+1][W+1];
        int [] w = new int[N];
        long [] v = new long[N];
        ct[0][0] = 1;
        for(int i=0;i<N;i++) {
            w[i] = ni();
            v[i] = nl();
        }
        for(int i=0;i<N;i++) {
            for(int j=0;j<=W;j++){
                dp[i+1][j] = Math.max(dp[i+1][j],dp[i][j]);
                if(j + w[i] <= W) dp[i+1][j+w[i]] = Math.max(dp[i+1][j+w[i]],dp[i][j]+v[i]);
            }
        }
        long base = dp[N][W] + 1;
        for(int i=1;i<=W;i++) {
            output.println(base-dp[N][W-i]);
        }
    }

    /* 関数 */



    /* 定数 */

    static PrintWriter output;
    static Scanner sc;
    static int  Inf = 1010101010; 
    static long Lnf = (long)1e18;
    static final long mod = 1000000007;
    static final long MOD = 998244353 ;

    /* 長いやつ  */

    static String cut(String S , int start, int end) { return S.substring(start,end);}
    static char cut(String S , int start) { return S.charAt(start);}
    static String tos(int val) { return Integer.toString(val);}
    static String tos(long val) { return Long.toString(val);}
    static int toi(String S) { return Integer.parseInt(S);}
    static long tol(String S) { return Long.parseLong(S);}

    /* 実装が面倒なやつ */

    public static long factorial(long n){
        return n <= 0 ? 1 : n * factorial(n-1);
    }

    public static int digits(long n) {
        return String.valueOf(n).length();
    }

    static boolean kaibun(String S) {
        StringBuilder s = new StringBuilder();
        s.append(S);
        return s.reverse().toString().equals(S);
    }

    static boolean isNumber(String value) {
        boolean result = false;
        if (value != null) {
            Pattern pattern = Pattern.compile("^[0-9]+$|-[0-9]+$");
            result = pattern.matcher(value).matches();
        }
        return result;
    }

    static Map<Integer,Integer> counter(int [] A) {
        HashMap<Integer,Integer> count = new HashMap<>();
        for(int i=0;i<A.length;i++) {
            if(!count.containsKey(A[i])) count.put(A[i],1);
            else count.put(A[i],count.get(A[i])+1);
        }
        return count;
    }

    static Map<Long,Integer> counter(long [] A) {
        HashMap<Long,Integer> count = new HashMap<>();
        for(int i=0;i<A.length;i++) {
            if(!count.containsKey(A[i])) count.put(A[i],1);
            else count.put(A[i],count.get(A[i])+1);
        }
        return count;
    }

    /*入出力端折るやつ*/

    static int ni(){ return Integer.parseInt(sc.next());}
    static long nl(){ return Long.parseLong(sc.next());}
    static double nd(){ return Double.parseDouble(sc.next());}
    static String ns(){ return sc.next();}
    static BigInteger bi(){ return sc.nextBigInteger();}
    static BigDecimal bd(){ return sc.nextBigDecimal();}
    
    static int [] IntArray(int n) {
        int [] Array = new int[n];
        for(int i=0;i<n;i++) Array[i] = ni();
        return Array;
    }
    static int [][] IntArray(int n , int m) {
        int [][] Array = new int[n][m];
        for(int i=0;i<n;i++) for(int j=0;j<m;j++) Array[i][j] = ni();
        return Array;
    }
    static long [] LongArray(int n) {
        long [] Array = new long[n];
        for(int i=0;i<n;i++) Array[i] = nl();
        return Array;
    }
    static long [][] LongArray(int n , int m) {
        long [][] Array = new long[n][m];
        for(int i=0;i<n;i++) for(int j=0;j<m;j++) Array[i][j] = nl();
        return Array;
    }
    static double [] DoubleArray(int n) {
        double [] Array = new double[n];
        for(int i=0;i<n;i++) Array[i] = nd();
        return Array;
    }
    static double [][] DoubleArray(int n , int m) {
        double [][] Array = new double[n][m];
        for(int i=0;i<n;i++) for(int j=0;j<m;j++) Array[i][j] = nd();
        return Array;
    }
    static String [] StringArray(int n) {
        String [] Array = new String[n];
        for(int i=0;i<n;i++) Array[i] = ns();
        return Array;
    }
    static String [][] StringArray(int n , int m) {
        String [][] Array = new String[n][m];
        for(int i=0;i<n;i++) for(int j=0;j<m;j++) Array[i][j] = ns();
        return Array;
    }
    static char [] CharArray(int n) {
        char [] Array = new char[n];
        String S = ns();
        for(int i=0;i<n;i++) Array[i] = S.charAt(i);
        return Array;
    }
    static char [][] CharArray(int n,int m) {
        char [][] Array = new char[n][m];
        for(int i=0;i<n;i++) {
            String S = ns();
            for(int j=0;j<m;j++) Array[i][j] = S.charAt(j);
        }
        return Array;
    }
    static void PrintArray(int [] A) {
        for(int i=0;i<A.length;i++) output.print(A[i]+" ");
        output.println();
    }
    static void PrintArray(long [] A) {
        for(int i=0;i<A.length;i++) output.print(A[i]+" ");
        output.println();
    }
    static void PrintArray(double [] A) {
        for(int i=0;i<A.length;i++) output.print(A[i]+" ");
        output.println();
    }
    static void PrintArray(boolean [] A) {
        for(int i=0;i<A.length;i++) output.print(A[i]+" ");
        output.println();
    }
    static void PrintArray(int [][] A) {
        for(int i=0;i<A.length;i++) {
            for(int j=0;j<A[i].length;j++) {
                if(A[i][j] == Inf) output.print("X ");
                else output.print(A[i][j]+" ");
            }
            output.println();
        }
    }
    static void PrintArray(long [][] A) {
        for(int i=0;i<A.length;i++) {
            for(int j=0;j<A[i].length;j++) {
                if(A[i][j] == Lnf) output.print("X ");
                else output.print(A[i][j]+" ");
            }
            output.println();
        }
    }
    static void PrintArray(boolean [][] A) {
        for(int i=0;i<A.length;i++) {
            for(int j=0;j<A[i].length;j++) {
                output.print(A[i][j]?"O":"X");
            }
            output.println();
        }
    }
    public static void main(String[] args){
        output = new PrintWriter(System.out);
        sc = new Scanner(System.in);
        solve();
        output.flush();
    }
}

0