結果
問題 | No.2686 商品券の使い道 |
ユーザー | tenten |
提出日時 | 2024-03-25 11:44:16 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,463 bytes |
コンパイル時間 | 2,480 ms |
コンパイル使用メモリ | 79,072 KB |
実行使用メモリ | 88,052 KB |
最終ジャッジ日時 | 2024-09-30 14:02:48 |
合計ジャッジ時間 | 14,973 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 194 ms
54,996 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 152 ms
54,496 KB |
testcase_17 | WA | - |
testcase_18 | AC | 155 ms
54,936 KB |
testcase_19 | WA | - |
testcase_20 | AC | 159 ms
54,480 KB |
testcase_21 | AC | 183 ms
54,980 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 151 ms
54,712 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 360 ms
87,428 KB |
testcase_31 | WA | - |
testcase_32 | AC | 332 ms
87,880 KB |
testcase_33 | AC | 354 ms
87,660 KB |
testcase_34 | WA | - |
testcase_35 | AC | 368 ms
87,908 KB |
testcase_36 | AC | 332 ms
87,472 KB |
testcase_37 | AC | 348 ms
87,632 KB |
testcase_38 | AC | 343 ms
87,696 KB |
testcase_39 | AC | 330 ms
87,724 KB |
testcase_40 | WA | - |
testcase_41 | AC | 363 ms
87,720 KB |
testcase_42 | WA | - |
testcase_43 | AC | 358 ms
87,760 KB |
testcase_44 | AC | 326 ms
87,744 KB |
testcase_45 | WA | - |
testcase_46 | WA | - |
evil_random20_1.txt | WA | - |
evil_random20_2.txt | WA | - |
evil_random20_3.txt | WA | - |
ソースコード
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 a = sc.nextInt(); int b = sc.nextInt(); int[] prices = new int[n]; int[] values = new int[n]; for (int i = 0; i < n; i++) { prices[i] = sc.nextInt(); values[i] = sc.nextInt(); } long[] weights = new long[1 << n]; long[][] dp = new long[1 << n][2]; for (int i = 0; i < (1 << n); i++) { for (int j = 0; j < n; j++) { if ((i & (1 << j)) == 0) { continue; } weights[i] = weights[i ^ (1 << j)] + prices[j]; if (weights[i] <= a) { dp[i][0] = dp[i ^ (1 << j)][0] + values[j]; } if (weights[j] <= b) { dp[i][1] = dp[i ^ (1 << j)][1] + values[j]; } break; } for (int j = 0; j < n; j++) { if ((i & (1 << j)) == 0) { continue; } dp[i][0] = Math.max(dp[i][0], dp[i ^ (1 << j)][0] + values[j]); dp[i][1] = Math.max(dp[i][1], dp[i ^ (1 << j)][1] + values[j]); } } long ans = 0; for (int i = 0; i < (1 << n); i++) { ans = Math.max(ans, dp[i][0] + dp[((1 << n) - 1) ^ i][1]); } 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(); } } }