結果

問題 No.1463 Hungry Kanten
ユーザー tentententen
提出日時 2021-04-13 12:10:08
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,761 bytes
コンパイル時間 2,464 ms
コンパイル使用メモリ 75,284 KB
実行使用メモリ 79,900 KB
最終ジャッジ日時 2023-09-11 23:52:58
合計ジャッジ時間 9,878 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,988 KB
testcase_01 AC 39 ms
49,552 KB
testcase_02 AC 1,154 ms
63,084 KB
testcase_03 TLE -
testcase_04 AC 44 ms
50,080 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

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<Number> nums = new HashSet<>();
        for (int i = 1; i < (1 << n); i++) {
            if (getPop(i) < k) {
                continue;
            }
            int sum = 0;
            Number mul = new Number(1);
            int x = i;
            for (int j = 0; j < n; j++) {
                if (x % 2 == 1) {
                    sum += arr[j];
                    mul.multiply(arr[j]);
                }
                x >>= 1;
            }
            nums.add(mul);
            nums.add(new Number(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