結果
| 問題 |
No.1463 Hungry Kanten
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2023-04-17 13:44:46 |
| 言語 | Java (openjdk 23) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 3,839 bytes |
| コンパイル時間 | 3,327 ms |
| コンパイル使用メモリ | 96,228 KB |
| 実行使用メモリ | 762,240 KB |
| 最終ジャッジ日時 | 2024-10-12 15:29:06 |
| 合計ジャッジ時間 | 8,196 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 4 RE * 15 TLE * 1 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int k = sc.nextInt();
int[] values = new int[n];
Num[] nums = new Num[n];
for (int i = 0; i < n; i++) {
values[i] = sc.nextInt();
nums[i] = new Num(values[i]);
}
int[] dp1 = new int[1 << n];
Num[] dp2 = new Num[1 << n];
dp2[0] = new Num(0);
HashSet<Num> ans = new HashSet<>();
for (int i = 1; i < (1 << n); i++) {
int pop = getPop(i);
for (int j = 0; j < n; j++) {
if ((i & (1 << j)) == 0) {
continue;
}
dp1[i] = dp1[i ^ (1 << j)] + values[j];
dp2[i] = dp2[i ^ (1 << j)].multiply(nums[j]);
break;
}
if (pop >= k) {
ans.add(new Num(dp1[i]));
ans.add(dp2[i]);
}
}
System.out.println(ans.size());
}
static int getPop(long x) {
int pop = 0;
while (x > 0) {
pop += x % 2;
x >>= 1;
}
return pop;
}
static class Num {
int[] counts = new int[1800];
public Num(int x) {
for (int i = 2; i <= Math.sqrt(x); i++) {
while (x % i == 0) {
counts[i]++;
x /= i;
}
}
if (x > 1) {
counts[x]++;
}
}
public Num multiply(Num x) {
Num ans = new Num(0);
for (int i = 0; i < counts.length; i++) {
ans.counts[i] = counts[i] + x.counts[i];
}
return ans;
}
public int hashCode() {
return counts[2];
}
public boolean equals(Object o) {
Num x = (Num)o;
for (int i = 0; i < counts.length; i++) {
if (counts[i] != x.counts[i]) {
return false;
}
}
return true;
}
public String toString() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < counts.length; i++) {
if (counts[i] > 0) {
sb.append("[").append(i).append(":").append(counts[i]).append("]");
}
}
return sb.toString();
}
}
}
class Utilities {
static String arrayToLineString(Object[] arr) {
return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
}
static String arrayToLineString(int[] arr) {
return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public int[] nextIntArray() throws Exception {
return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
}
public String next() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten