結果

問題 No.1463 Hungry Kanten
ユーザー tentententen
提出日時 2021-04-13 12:19:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 888 ms / 2,000 ms
コード長 2,831 bytes
コンパイル時間 2,438 ms
コンパイル使用メモリ 75,380 KB
実行使用メモリ 105,260 KB
最終ジャッジ日時 2023-09-11 23:58:00
合計ジャッジ時間 7,283 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,284 KB
testcase_01 AC 41 ms
49,336 KB
testcase_02 AC 112 ms
54,992 KB
testcase_03 AC 413 ms
59,344 KB
testcase_04 AC 43 ms
49,332 KB
testcase_05 AC 888 ms
105,260 KB
testcase_06 AC 42 ms
49,404 KB
testcase_07 AC 41 ms
49,612 KB
testcase_08 AC 44 ms
49,508 KB
testcase_09 AC 43 ms
47,532 KB
testcase_10 AC 46 ms
50,088 KB
testcase_11 AC 51 ms
51,216 KB
testcase_12 AC 55 ms
50,984 KB
testcase_13 AC 49 ms
51,132 KB
testcase_14 AC 86 ms
55,116 KB
testcase_15 AC 59 ms
51,288 KB
testcase_16 AC 112 ms
55,352 KB
testcase_17 AC 208 ms
60,464 KB
testcase_18 AC 98 ms
56,984 KB
testcase_19 AC 558 ms
76,428 KB
testcase_20 AC 721 ms
85,656 KB
testcase_21 AC 53 ms
50,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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