結果
問題 | No.1463 Hungry Kanten |
ユーザー |
![]() |
提出日時 | 2021-04-02 21:29:28 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,116 ms / 2,000 ms |
コード長 | 802 bytes |
コンパイル時間 | 2,578 ms |
コンパイル使用メモリ | 78,000 KB |
実行使用メモリ | 93,760 KB |
最終ジャッジ日時 | 2024-12-23 23:18:43 |
合計ジャッジ時間 | 9,548 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
import java.math.BigInteger; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); BigInteger[] a = new BigInteger[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextBigInteger(); } sc.close(); Set<BigInteger> set = new HashSet<>(); int end = 1 << n; for (int i = 0; i < end; i++) { if (Integer.bitCount(i) < k) { continue; } BigInteger x = BigInteger.ZERO; BigInteger y = BigInteger.ONE; for (int j = 0; j < n; j++) { if ((i >> j & 1) == 1) { x = x.add(a[j]); y = y.multiply(a[j]); } } set.add(x); set.add(y); } System.out.println(set.size()); } }