結果

問題 No.1463 Hungry Kanten
ユーザー tentententen
提出日時 2024-02-07 17:52:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 894 ms / 2,000 ms
コード長 2,110 bytes
コンパイル時間 2,732 ms
コンパイル使用メモリ 88,248 KB
実行使用メモリ 132,412 KB
最終ジャッジ日時 2024-02-07 17:52:17
合計ジャッジ時間 9,054 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
54,888 KB
testcase_01 AC 73 ms
55,020 KB
testcase_02 AC 157 ms
61,400 KB
testcase_03 AC 462 ms
103,692 KB
testcase_04 AC 104 ms
55,256 KB
testcase_05 AC 894 ms
132,412 KB
testcase_06 AC 71 ms
55,020 KB
testcase_07 AC 70 ms
54,884 KB
testcase_08 AC 71 ms
55,032 KB
testcase_09 AC 81 ms
55,008 KB
testcase_10 AC 78 ms
55,132 KB
testcase_11 AC 83 ms
55,140 KB
testcase_12 AC 103 ms
55,260 KB
testcase_13 AC 102 ms
55,284 KB
testcase_14 AC 129 ms
58,676 KB
testcase_15 AC 155 ms
60,108 KB
testcase_16 AC 154 ms
59,604 KB
testcase_17 AC 200 ms
64,140 KB
testcase_18 AC 202 ms
68,932 KB
testcase_19 AC 499 ms
93,016 KB
testcase_20 AC 681 ms
126,396 KB
testcase_21 AC 96 ms
55,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        List<BigInteger> values = IntStream.range(0, n).mapToObj(i -> new BigInteger(sc.next())).toList();
        BigInteger[] sum = new BigInteger[1 << n];
        BigInteger[] multi = new BigInteger[1 << n];
        sum[0] = new BigInteger("0");
        multi[0] = new BigInteger("1");
        HashSet<BigInteger> ans = new HashSet<>();
        IntStream.range(1, 1 << n).forEach(i -> {
            int idx = IntStream.range(0, n).filter(j -> (i & (1 << j)) > 0).findFirst().orElse(0);
            sum[i] = sum[i ^ (1 << idx)].add(values.get(idx));
            multi[i] = multi[i ^ (1 << idx)].multiply(values.get(idx));
            if (getPop(i) >= k) {
                ans.add(sum[i]);
                ans.add(multi[i]);
            }
        });
        System.out.println(ans.size());
    }
    
    static int getPop(int x) {
        int pop = 0;
        while (x > 0) {
            pop += x % 2;
            x >>= 1;
        }
        return pop;
    }
}
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