結果
問題 | No.1463 Hungry Kanten |
ユーザー |
![]() |
提出日時 | 2024-02-07 14:22:00 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,965 bytes |
コンパイル時間 | 2,629 ms |
コンパイル使用メモリ | 87,932 KB |
実行使用メモリ | 79,748 KB |
最終ジャッジ日時 | 2024-09-28 12:30:36 |
合計ジャッジ時間 | 7,821 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 WA * 3 |
ソースコード
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 k = sc.nextInt();List<Integer> values = Stream.generate(sc::nextInt).limit(n).toList();long[] sum = new long[1 << n];long[] multi = new long[1 << n];multi[0] = 1;HashSet<Long> 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)] + values.get(idx);multi[i] = multi[i ^ (1 << idx)] * 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();}}}