結果
| 問題 |
No.626 Randomized 01 Knapsack
|
| コンテスト | |
| ユーザー |
夕叢霧香(ゆうむらきりか)
|
| 提出日時 | 2017-12-15 21:19:14 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,217 bytes |
| コンパイル時間 | 2,475 ms |
| コンパイル使用メモリ | 77,900 KB |
| 実行使用メモリ | 46,128 KB |
| 最終ジャッジ日時 | 2024-12-15 08:20:12 |
| 合計ジャッジ時間 | 18,939 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 WA * 5 |
ソースコード
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=50;
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;
}
}
}
夕叢霧香(ゆうむらきりか)