結果
問題 | No.2686 商品券の使い道 |
ユーザー | tenten |
提出日時 | 2024-03-25 11:54:17 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 365 ms / 3,000 ms |
コード長 | 2,439 bytes |
コンパイル時間 | 2,357 ms |
コンパイル使用メモリ | 79,204 KB |
実行使用メモリ | 88,052 KB |
最終ジャッジ日時 | 2024-09-30 14:03:05 |
合計ジャッジ時間 | 14,683 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
37,136 KB |
testcase_01 | AC | 52 ms
36,920 KB |
testcase_02 | AC | 161 ms
55,028 KB |
testcase_03 | AC | 159 ms
55,000 KB |
testcase_04 | AC | 159 ms
55,028 KB |
testcase_05 | AC | 157 ms
55,028 KB |
testcase_06 | AC | 147 ms
55,056 KB |
testcase_07 | AC | 144 ms
54,284 KB |
testcase_08 | AC | 148 ms
54,516 KB |
testcase_09 | AC | 148 ms
54,744 KB |
testcase_10 | AC | 167 ms
54,856 KB |
testcase_11 | AC | 142 ms
54,856 KB |
testcase_12 | AC | 150 ms
54,856 KB |
testcase_13 | AC | 187 ms
54,780 KB |
testcase_14 | AC | 152 ms
54,796 KB |
testcase_15 | AC | 144 ms
54,728 KB |
testcase_16 | AC | 174 ms
54,964 KB |
testcase_17 | AC | 148 ms
54,904 KB |
testcase_18 | AC | 174 ms
54,680 KB |
testcase_19 | AC | 173 ms
54,840 KB |
testcase_20 | AC | 158 ms
54,776 KB |
testcase_21 | AC | 177 ms
55,040 KB |
testcase_22 | AC | 150 ms
54,692 KB |
testcase_23 | AC | 145 ms
54,596 KB |
testcase_24 | AC | 151 ms
54,536 KB |
testcase_25 | AC | 153 ms
54,600 KB |
testcase_26 | AC | 172 ms
54,836 KB |
testcase_27 | AC | 144 ms
54,712 KB |
testcase_28 | AC | 173 ms
54,852 KB |
testcase_29 | AC | 291 ms
87,596 KB |
testcase_30 | AC | 299 ms
87,452 KB |
testcase_31 | AC | 325 ms
87,732 KB |
testcase_32 | AC | 346 ms
88,008 KB |
testcase_33 | AC | 288 ms
87,596 KB |
testcase_34 | AC | 330 ms
87,912 KB |
testcase_35 | AC | 307 ms
87,948 KB |
testcase_36 | AC | 324 ms
87,976 KB |
testcase_37 | AC | 358 ms
87,848 KB |
testcase_38 | AC | 350 ms
87,872 KB |
testcase_39 | AC | 337 ms
87,764 KB |
testcase_40 | AC | 327 ms
87,876 KB |
testcase_41 | AC | 318 ms
87,608 KB |
testcase_42 | AC | 336 ms
87,736 KB |
testcase_43 | AC | 351 ms
87,608 KB |
testcase_44 | AC | 343 ms
87,452 KB |
testcase_45 | AC | 338 ms
87,728 KB |
testcase_46 | AC | 365 ms
88,052 KB |
evil_random20_1.txt | AC | 355 ms
87,824 KB |
evil_random20_2.txt | AC | 342 ms
87,752 KB |
evil_random20_3.txt | AC | 305 ms
87,664 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 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[i] <= 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]); dp[i][1] = Math.max(dp[i][1], dp[i ^ (1 << j)][1]); } } 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(); } } }