結果
問題 | No.2686 商品券の使い道 |
ユーザー | tenten |
提出日時 | 2024-03-25 11:29:18 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,184 bytes |
コンパイル時間 | 2,080 ms |
コンパイル使用メモリ | 78,120 KB |
実行使用メモリ | 96,136 KB |
最終ジャッジ日時 | 2024-03-25 11:29:48 |
合計ジャッジ時間 | 28,364 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
54,012 KB |
testcase_01 | AC | 48 ms
53,992 KB |
testcase_02 | AC | 118 ms
64,744 KB |
testcase_03 | AC | 133 ms
64,748 KB |
testcase_04 | AC | 144 ms
64,728 KB |
testcase_05 | AC | 128 ms
64,720 KB |
testcase_06 | AC | 122 ms
64,720 KB |
testcase_07 | AC | 126 ms
64,620 KB |
testcase_08 | AC | 126 ms
64,744 KB |
testcase_09 | AC | 124 ms
64,728 KB |
testcase_10 | AC | 139 ms
64,744 KB |
testcase_11 | AC | 1,446 ms
64,748 KB |
testcase_12 | AC | 175 ms
62,832 KB |
testcase_13 | AC | 1,665 ms
64,712 KB |
testcase_14 | AC | 1,302 ms
64,712 KB |
testcase_15 | AC | 613 ms
64,752 KB |
testcase_16 | AC | 1,170 ms
64,688 KB |
testcase_17 | AC | 733 ms
64,756 KB |
testcase_18 | AC | 471 ms
64,688 KB |
testcase_19 | AC | 525 ms
64,736 KB |
testcase_20 | AC | 1,777 ms
64,752 KB |
testcase_21 | AC | 1,760 ms
64,700 KB |
testcase_22 | AC | 456 ms
64,724 KB |
testcase_23 | AC | 896 ms
64,740 KB |
testcase_24 | AC | 1,268 ms
64,740 KB |
testcase_25 | AC | 150 ms
64,696 KB |
testcase_26 | AC | 443 ms
62,744 KB |
testcase_27 | AC | 1,635 ms
64,668 KB |
testcase_28 | AC | 115 ms
64,232 KB |
testcase_29 | AC | 2,727 ms
89,384 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; } ans = Math.max(ans, dp[i][1]); 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(); } } }