結果
問題 | No.2232 Miser's Gift |
ユーザー | tenten |
提出日時 | 2023-08-08 18:59:20 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 426 ms / 2,000 ms |
コード長 | 2,502 bytes |
コンパイル時間 | 4,206 ms |
コンパイル使用メモリ | 91,884 KB |
実行使用メモリ | 96,712 KB |
最終ジャッジ日時 | 2024-11-09 02:16:12 |
合計ジャッジ時間 | 20,657 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
37,004 KB |
testcase_01 | AC | 53 ms
37,212 KB |
testcase_02 | AC | 54 ms
37,144 KB |
testcase_03 | AC | 332 ms
80,064 KB |
testcase_04 | AC | 336 ms
96,220 KB |
testcase_05 | AC | 139 ms
46,596 KB |
testcase_06 | AC | 53 ms
37,124 KB |
testcase_07 | AC | 150 ms
44,372 KB |
testcase_08 | AC | 365 ms
96,512 KB |
testcase_09 | AC | 362 ms
96,508 KB |
testcase_10 | AC | 364 ms
96,532 KB |
testcase_11 | AC | 364 ms
96,684 KB |
testcase_12 | AC | 365 ms
96,328 KB |
testcase_13 | AC | 332 ms
80,456 KB |
testcase_14 | AC | 331 ms
80,568 KB |
testcase_15 | AC | 335 ms
80,400 KB |
testcase_16 | AC | 328 ms
80,140 KB |
testcase_17 | AC | 332 ms
79,972 KB |
testcase_18 | AC | 328 ms
80,048 KB |
testcase_19 | AC | 330 ms
80,252 KB |
testcase_20 | AC | 332 ms
80,036 KB |
testcase_21 | AC | 330 ms
80,188 KB |
testcase_22 | AC | 328 ms
79,936 KB |
testcase_23 | AC | 426 ms
96,084 KB |
testcase_24 | AC | 391 ms
95,792 KB |
testcase_25 | AC | 403 ms
96,440 KB |
testcase_26 | AC | 402 ms
96,712 KB |
testcase_27 | AC | 400 ms
96,144 KB |
testcase_28 | AC | 366 ms
96,148 KB |
testcase_29 | AC | 365 ms
96,464 KB |
testcase_30 | AC | 364 ms
96,592 KB |
testcase_31 | AC | 363 ms
96,624 KB |
testcase_32 | AC | 363 ms
96,500 KB |
testcase_33 | AC | 345 ms
95,568 KB |
testcase_34 | AC | 348 ms
96,180 KB |
testcase_35 | AC | 348 ms
95,704 KB |
testcase_36 | AC | 340 ms
80,716 KB |
testcase_37 | AC | 351 ms
96,116 KB |
testcase_38 | AC | 82 ms
38,000 KB |
testcase_39 | AC | 71 ms
38,108 KB |
testcase_40 | AC | 80 ms
38,348 KB |
testcase_41 | AC | 79 ms
38,088 KB |
testcase_42 | AC | 81 ms
38,028 KB |
testcase_43 | AC | 80 ms
38,076 KB |
testcase_44 | AC | 79 ms
38,292 KB |
testcase_45 | AC | 72 ms
38,120 KB |
testcase_46 | AC | 79 ms
38,336 KB |
testcase_47 | AC | 78 ms
38,136 KB |
testcase_48 | AC | 57 ms
36,976 KB |
testcase_49 | AC | 57 ms
37,228 KB |
testcase_50 | AC | 56 ms
37,112 KB |
testcase_51 | AC | 57 ms
36,864 KB |
testcase_52 | AC | 57 ms
36,800 KB |
testcase_53 | AC | 58 ms
37,188 KB |
testcase_54 | AC | 57 ms
36,952 KB |
testcase_55 | AC | 58 ms
36,956 KB |
testcase_56 | AC | 55 ms
37,260 KB |
testcase_57 | AC | 56 ms
37,076 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static int[] weights; static int[] values; static int[][] dp; 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[] results = new int[w + 1]; for (int i = 1; i <= w; i++) { results[i] = dfw(n - 1, i); } StringBuilder sb = new StringBuilder(); for (int i = 1; i <= w; i++) { sb.append(results[w] - results[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(); } }