結果

問題 No.626 Randomized 01 Knapsack
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2017-12-15 21:13:54
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,124 bytes
コンパイル時間 3,362 ms
コンパイル使用メモリ 74,548 KB
実行使用メモリ 59,528 KB
最終ジャッジ日時 2023-08-21 18:33:59
合計ジャッジ時間 30,333 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
53,892 KB
testcase_01 AC 99 ms
54,200 KB
testcase_02 AC 133 ms
54,324 KB
testcase_03 AC 123 ms
53,552 KB
testcase_04 AC 186 ms
54,212 KB
testcase_05 AC 107 ms
54,388 KB
testcase_06 AC 607 ms
54,696 KB
testcase_07 AC 572 ms
54,588 KB
testcase_08 AC 862 ms
54,456 KB
testcase_09 AC 775 ms
55,412 KB
testcase_10 AC 1,455 ms
54,964 KB
testcase_11 AC 1,689 ms
55,612 KB
testcase_12 AC 1,990 ms
56,148 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1,505 ms
55,416 KB
testcase_16 TLE -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 TLE -
testcase_21 WA -
testcase_22 AC 1,371 ms
55,620 KB
testcase_23 AC 1,860 ms
53,772 KB
testcase_24 AC 135 ms
55,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        long ww=sc.nextLong();
        int U=64;
        int W=5001*U;
        long D=Math.max(1,ww/U/n);
        long[]v=new long[n],w=new long[n];
        int[]vt=new int[n];
        for(int i=0;i<n;++i){
            v[i]=sc.nextInt();
            w[i]=sc.nextInt();
            vt[i]=w[i]>ww?W:(int)((w[i]+D-1)/D);
        }
        long[]dp=new long[W];
        Arrays.fill(dp,0);
        for(int i=0;i<n;++i){
            for(int j=W-1;j>=vt[i];--j)
                dp[j]=Math.max(dp[j],dp[j-vt[i]]+v[i]);
        }
        long ans=0;
        for(int i=0;i<W&&i*D<=ww;++i)ans=Math.max(ans,dp[i]);
        out.println(ans);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}
0