結果

問題 No.1463 Hungry Kanten
ユーザー ks2mks2m
提出日時 2021-04-02 21:29:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 843 ms / 2,000 ms
コード長 802 bytes
コンパイル時間 2,202 ms
コンパイル使用メモリ 76,304 KB
実行使用メモリ 104,680 KB
最終ジャッジ日時 2023-08-25 14:46:59
合計ジャッジ時間 8,371 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,116 KB
testcase_01 AC 120 ms
55,792 KB
testcase_02 AC 195 ms
58,952 KB
testcase_03 AC 435 ms
63,760 KB
testcase_04 AC 124 ms
55,860 KB
testcase_05 AC 843 ms
104,680 KB
testcase_06 AC 123 ms
56,092 KB
testcase_07 AC 123 ms
56,284 KB
testcase_08 AC 122 ms
55,732 KB
testcase_09 AC 123 ms
56,504 KB
testcase_10 AC 128 ms
56,380 KB
testcase_11 AC 124 ms
56,056 KB
testcase_12 AC 131 ms
56,040 KB
testcase_13 AC 129 ms
56,180 KB
testcase_14 AC 165 ms
58,108 KB
testcase_15 AC 131 ms
56,232 KB
testcase_16 AC 177 ms
58,720 KB
testcase_17 AC 244 ms
62,820 KB
testcase_18 AC 173 ms
58,528 KB
testcase_19 AC 544 ms
79,116 KB
testcase_20 AC 723 ms
87,848 KB
testcase_21 AC 129 ms
55,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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());
	}
}
0