結果

問題 No.2686 商品券の使い道
ユーザー tentententen
提出日時 2024-03-25 11:44:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,463 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 78,964 KB
実行使用メモリ 103,168 KB
最終ジャッジ日時 2024-03-25 11:44:33
合計ジャッジ時間 14,425 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 176 ms
68,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 150 ms
68,400 KB
testcase_17 WA -
testcase_18 AC 156 ms
68,276 KB
testcase_19 WA -
testcase_20 AC 137 ms
68,108 KB
testcase_21 AC 165 ms
68,452 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 138 ms
68,168 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 311 ms
102,808 KB
testcase_31 WA -
testcase_32 AC 286 ms
103,052 KB
testcase_33 AC 339 ms
102,800 KB
testcase_34 WA -
testcase_35 AC 331 ms
103,056 KB
testcase_36 AC 286 ms
103,032 KB
testcase_37 AC 327 ms
103,016 KB
testcase_38 AC 299 ms
103,048 KB
testcase_39 AC 279 ms
103,052 KB
testcase_40 WA -
testcase_41 AC 345 ms
103,048 KB
testcase_42 WA -
testcase_43 AC 314 ms
103,004 KB
testcase_44 AC 321 ms
103,004 KB
testcase_45 WA -
testcase_46 WA -
evil_random20_1.txt WA -
evil_random20_2.txt WA -
evil_random20_3.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        }
    }
    
}
0