結果
問題 | No.2686 商品券の使い道 |
ユーザー |
![]() |
提出日時 | 2024-03-25 11:26:21 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,141 bytes |
コンパイル時間 | 2,357 ms |
コンパイル使用メモリ | 78,500 KB |
実行使用メモリ | 82,256 KB |
最終ジャッジ日時 | 2024-09-30 14:01:57 |
合計ジャッジ時間 | 29,339 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
42,152 KB |
testcase_01 | AC | 53 ms
37,016 KB |
testcase_02 | AC | 143 ms
50,332 KB |
testcase_03 | AC | 154 ms
50,300 KB |
testcase_04 | AC | 166 ms
50,360 KB |
testcase_05 | AC | 149 ms
50,008 KB |
testcase_06 | AC | 147 ms
50,424 KB |
testcase_07 | WA | - |
testcase_08 | AC | 141 ms
50,472 KB |
testcase_09 | AC | 143 ms
50,200 KB |
testcase_10 | AC | 164 ms
50,260 KB |
testcase_11 | AC | 1,574 ms
50,236 KB |
testcase_12 | AC | 208 ms
50,496 KB |
testcase_13 | AC | 1,701 ms
50,212 KB |
testcase_14 | AC | 1,510 ms
50,004 KB |
testcase_15 | AC | 693 ms
50,236 KB |
testcase_16 | AC | 1,211 ms
50,376 KB |
testcase_17 | AC | 730 ms
50,152 KB |
testcase_18 | AC | 526 ms
50,292 KB |
testcase_19 | AC | 566 ms
50,008 KB |
testcase_20 | AC | 1,321 ms
50,456 KB |
testcase_21 | AC | 1,955 ms
50,504 KB |
testcase_22 | AC | 489 ms
50,376 KB |
testcase_23 | AC | 906 ms
50,204 KB |
testcase_24 | AC | 1,374 ms
50,240 KB |
testcase_25 | AC | 177 ms
50,484 KB |
testcase_26 | AC | 557 ms
50,240 KB |
testcase_27 | AC | 1,677 ms
50,308 KB |
testcase_28 | AC | 136 ms
49,956 KB |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
evil_random20_1.txt | -- | - |
evil_random20_2.txt | -- | - |
evil_random20_3.txt | -- | - |
ソースコード
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[][] 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; } dp[i][0] = dp[i ^ (1 << j)][0] + prices[j]; dp[i][1] = dp[i ^ (1 << j)][1] + values[j]; } } long ans = 0; for (int i = 0; i < (1 << n); i++) { if (dp[i][0] > a) { continue; } int base = ((1 << n) - 1) ^ i; for (int j = base; j > 0; j = ((j - 1) & base)) { if (dp[j][0] <= b) { ans = Math.max(ans, dp[i][1] + dp[j][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(); } } }