結果
| 問題 | No.1463 Hungry Kanten | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2021-04-13 12:19:13 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 697 ms / 2,000 ms | 
| コード長 | 2,831 bytes | 
| コンパイル時間 | 3,045 ms | 
| コンパイル使用メモリ | 81,900 KB | 
| 実行使用メモリ | 81,988 KB | 
| 最終ジャッジ日時 | 2025-06-20 01:36:48 | 
| 合計ジャッジ時間 | 7,816 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 24 | 
ソースコード
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        HashSet<BigInteger> nums = new HashSet<>();
        for (int i = 1; i < (1 << n); i++) {
            if (getPop(i) < k) {
                continue;
            }
            int sum = 0;
            BigInteger mul = BigInteger.valueOf(1);
            int x = i;
            for (int j = 0; j < n; j++) {
                if (x % 2 == 1) {
                    sum += arr[j];
                    mul = mul.multiply(BigInteger.valueOf(arr[j]));
                }
                x >>= 1;
            }
            nums.add(mul);
            nums.add(BigInteger.valueOf(sum));
        }
        System.out.println(nums.size());
    }
    
    static int getPop(int x) {
        int pop = 0;
        while (x > 0) {
            pop += x % 2;
            x >>= 1;
        }
        return pop;
    }
    
    static class Number {
        HashMap<Integer, Integer> map = new HashMap<>();
        
        public Number(int x) {
            multiply(x);
        }
        
        public void multiply(int x) {
            for (int i = 2; i <= Math.sqrt(x); i++) {
                while (x % i == 0) {
                    map.put(i, map.getOrDefault(i, 0) + 1);
                    x /= i;
                }
            }
            if (x > 1) {
                map.put(x, map.getOrDefault(x, 0) + 1);
            }
        }
        
        public int hashCode() {
            return map.size();
        }
        
        public boolean equals(Object o) {
            Number n = (Number)o;
            if (map.size() != n.map.size()) {
                return false;
            }
            for (int x : map.keySet()) {
                if (!n.map.containsKey(x) || map.get(x) != n.map.get(x)) {
                    return false;
                }
            }
            return true;
        }
        
        public String toString() {
            return map.toString();
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
            
            
            
        