結果
| 問題 |
No.1463 Hungry Kanten
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-04-13 12:10:08 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,761 bytes |
| コンパイル時間 | 2,585 ms |
| コンパイル使用メモリ | 78,352 KB |
| 実行使用メモリ | 84,888 KB |
| 最終ジャッジ日時 | 2024-06-29 13:11:08 |
| 合計ジャッジ時間 | 9,820 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 2 TLE * 2 -- * 16 |
ソースコード
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();
}
}
tenten