結果
問題 | No.1463 Hungry Kanten |
ユーザー | tenten |
提出日時 | 2024-02-07 14:22:00 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,965 bytes |
コンパイル時間 | 2,667 ms |
コンパイル使用メモリ | 88,076 KB |
実行使用メモリ | 93,416 KB |
最終ジャッジ日時 | 2024-02-07 14:22:09 |
合計ジャッジ時間 | 8,203 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 84 ms
55,008 KB |
testcase_01 | AC | 84 ms
55,012 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 659 ms
93,416 KB |
testcase_06 | AC | 82 ms
55,012 KB |
testcase_07 | AC | 84 ms
55,016 KB |
testcase_08 | AC | 86 ms
55,008 KB |
testcase_09 | AC | 85 ms
55,024 KB |
testcase_10 | AC | 91 ms
55,020 KB |
testcase_11 | AC | 95 ms
55,264 KB |
testcase_12 | AC | 113 ms
55,400 KB |
testcase_13 | AC | 105 ms
55,264 KB |
testcase_14 | AC | 137 ms
56,552 KB |
testcase_15 | AC | 140 ms
58,708 KB |
testcase_16 | AC | 177 ms
59,392 KB |
testcase_17 | AC | 206 ms
59,832 KB |
testcase_18 | AC | 196 ms
61,532 KB |
testcase_19 | AC | 424 ms
74,864 KB |
testcase_20 | AC | 507 ms
80,060 KB |
testcase_21 | AC | 105 ms
55,180 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 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(); } } }