結果
| 問題 |
No.1463 Hungry Kanten
|
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2021-04-02 21:29:28 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 791 ms / 2,000 ms |
| コード長 | 802 bytes |
| コンパイル時間 | 3,024 ms |
| コンパイル使用メモリ | 87,048 KB |
| 実行使用メモリ | 84,044 KB |
| 最終ジャッジ日時 | 2025-06-20 01:30:50 |
| 合計ジャッジ時間 | 8,615 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 |
ソースコード
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());
}
}
ks2m