結果
問題 | No.2686 商品券の使い道 |
ユーザー | tenten |
提出日時 | 2024-03-25 11:26:21 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,141 bytes |
コンパイル時間 | 2,251 ms |
コンパイル使用メモリ | 78,920 KB |
実行使用メモリ | 103,944 KB |
最終ジャッジ日時 | 2024-03-25 11:26:51 |
合計ジャッジ時間 | 29,213 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
53,976 KB |
testcase_01 | AC | 50 ms
53,996 KB |
testcase_02 | AC | 127 ms
64,748 KB |
testcase_03 | AC | 138 ms
64,704 KB |
testcase_04 | AC | 147 ms
64,656 KB |
testcase_05 | AC | 127 ms
62,728 KB |
testcase_06 | AC | 162 ms
64,652 KB |
testcase_07 | WA | - |
testcase_08 | AC | 124 ms
64,624 KB |
testcase_09 | AC | 124 ms
64,636 KB |
testcase_10 | AC | 145 ms
64,636 KB |
testcase_11 | AC | 1,547 ms
64,632 KB |
testcase_12 | AC | 225 ms
64,648 KB |
testcase_13 | AC | 1,786 ms
64,644 KB |
testcase_14 | AC | 1,530 ms
64,648 KB |
testcase_15 | AC | 672 ms
64,720 KB |
testcase_16 | AC | 1,207 ms
62,728 KB |
testcase_17 | AC | 717 ms
64,756 KB |
testcase_18 | AC | 481 ms
64,716 KB |
testcase_19 | AC | 547 ms
64,652 KB |
testcase_20 | AC | 1,343 ms
64,872 KB |
testcase_21 | AC | 1,940 ms
64,904 KB |
testcase_22 | AC | 481 ms
64,716 KB |
testcase_23 | AC | 923 ms
64,624 KB |
testcase_24 | AC | 1,406 ms
64,640 KB |
testcase_25 | AC | 155 ms
64,712 KB |
testcase_26 | AC | 493 ms
64,648 KB |
testcase_27 | AC | 1,693 ms
64,628 KB |
testcase_28 | AC | 130 ms
64,240 KB |
testcase_29 | AC | 2,733 ms
89,488 KB |
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(); } } }