結果
問題 | No.2730 Two Types Luggage |
ユーザー | tenten |
提出日時 | 2024-08-02 16:31:27 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 746 ms / 2,000 ms |
コード長 | 2,356 bytes |
コンパイル時間 | 2,088 ms |
コンパイル使用メモリ | 78,772 KB |
実行使用メモリ | 97,324 KB |
最終ジャッジ日時 | 2024-08-02 16:31:54 |
合計ジャッジ時間 | 25,010 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
37,264 KB |
testcase_01 | AC | 46 ms
37,436 KB |
testcase_02 | AC | 44 ms
37,340 KB |
testcase_03 | AC | 55 ms
36,936 KB |
testcase_04 | AC | 63 ms
39,228 KB |
testcase_05 | AC | 49 ms
37,544 KB |
testcase_06 | AC | 47 ms
37,408 KB |
testcase_07 | AC | 48 ms
37,016 KB |
testcase_08 | AC | 48 ms
37,340 KB |
testcase_09 | AC | 52 ms
37,480 KB |
testcase_10 | AC | 170 ms
43,704 KB |
testcase_11 | AC | 617 ms
68,784 KB |
testcase_12 | AC | 686 ms
96,992 KB |
testcase_13 | AC | 626 ms
67,016 KB |
testcase_14 | AC | 602 ms
68,948 KB |
testcase_15 | AC | 382 ms
64,308 KB |
testcase_16 | AC | 383 ms
54,796 KB |
testcase_17 | AC | 732 ms
88,752 KB |
testcase_18 | AC | 668 ms
87,528 KB |
testcase_19 | AC | 210 ms
45,848 KB |
testcase_20 | AC | 440 ms
54,524 KB |
testcase_21 | AC | 656 ms
68,672 KB |
testcase_22 | AC | 615 ms
89,324 KB |
testcase_23 | AC | 222 ms
46,108 KB |
testcase_24 | AC | 616 ms
56,552 KB |
testcase_25 | AC | 607 ms
69,048 KB |
testcase_26 | AC | 328 ms
52,700 KB |
testcase_27 | AC | 604 ms
68,512 KB |
testcase_28 | AC | 438 ms
55,568 KB |
testcase_29 | AC | 710 ms
87,444 KB |
testcase_30 | AC | 320 ms
63,056 KB |
testcase_31 | AC | 615 ms
66,392 KB |
testcase_32 | AC | 575 ms
65,744 KB |
testcase_33 | AC | 746 ms
96,892 KB |
testcase_34 | AC | 620 ms
97,324 KB |
testcase_35 | AC | 712 ms
97,256 KB |
testcase_36 | AC | 742 ms
97,260 KB |
testcase_37 | AC | 692 ms
97,228 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); long w = sc.nextLong(); int[] values = new int[n]; for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); } Arrays.sort(values); long[] sums = new long[n + 1]; for (int i = 1; i <= n; i++) { sums[i] = sums[i - 1] + values[n - i]; } int[] weights = new int[m]; for (int i = 0; i < m; i++) { weights[i] = sc.nextInt(); } int[] contains = new int[m]; for (int i = 0; i < m; i++) { contains[i] = sc.nextInt(); } long[] dpWeights = new long[1 << m]; long[] dp = new long[1 << m]; long ans = sums[(int)Math.min(w, n)]; for (int i = 1; i < (1 << m); i++) { for (int j = 0; j < m; j++) { if ((i & (1 << j)) == 0) { continue; } dpWeights[i] = dpWeights[i ^ (1 << j)] + weights[j]; dp[i] = dp[i ^ (1 << j)] + contains[j]; break; } if (w >= dpWeights[i]) { ans = Math.max(ans, dp[i] + sums[(int)Math.min(w - dpWeights[i], n)]); } } System.out.println(ans); } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }