結果
問題 | No.626 Randomized 01 Knapsack |
ユーザー | 夕叢霧香(ゆうむらきりか) |
提出日時 | 2017-12-15 21:18:44 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,217 bytes |
コンパイル時間 | 4,871 ms |
コンパイル使用メモリ | 73,916 KB |
実行使用メモリ | 57,136 KB |
最終ジャッジ日時 | 2023-08-21 18:34:31 |
合計ジャッジ時間 | 17,303 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
49,296 KB |
testcase_01 | AC | 46 ms
49,332 KB |
testcase_02 | AC | 50 ms
49,388 KB |
testcase_03 | AC | 54 ms
49,516 KB |
testcase_04 | AC | 64 ms
51,636 KB |
testcase_05 | AC | 61 ms
50,396 KB |
testcase_06 | WA | - |
testcase_07 | AC | 116 ms
52,304 KB |
testcase_08 | AC | 125 ms
51,936 KB |
testcase_09 | AC | 190 ms
53,160 KB |
testcase_10 | AC | 331 ms
53,156 KB |
testcase_11 | AC | 1,083 ms
55,272 KB |
testcase_12 | AC | 1,279 ms
53,496 KB |
testcase_13 | AC | 175 ms
55,356 KB |
testcase_14 | AC | 391 ms
55,004 KB |
testcase_15 | WA | - |
testcase_16 | AC | 1,237 ms
54,844 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 1,393 ms
55,000 KB |
testcase_21 | AC | 174 ms
54,756 KB |
testcase_22 | AC | 894 ms
55,040 KB |
testcase_23 | AC | 1,212 ms
55,292 KB |
testcase_24 | AC | 140 ms
55,584 KB |
ソースコード
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=40; int p=0; long[]v=new long[n],w=new long[n]; for(int i=0;i<n;++i){ v[p]=sc.nextInt(); w[p]=sc.nextInt(); if(w[i]>ww)continue; p++; } long D=Math.max(1,(ww+U*p-1)/U/p); int[]vt=new int[p]; for(int i=0;i<p;++i) vt[i]=(int)((w[i]+D-1)/D); int W=p*U+1; long[]dp=new long[W]; Arrays.fill(dp,0); for(int i=0;i<p;++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; } } }