結果
| 問題 |
No.68 よくある棒を切る問題 (2)
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2023-08-10 13:37:24 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,232 ms / 5,000 ms |
| コード長 | 3,337 bytes |
| コンパイル時間 | 3,174 ms |
| コンパイル使用メモリ | 87,200 KB |
| 実行使用メモリ | 75,572 KB |
| 最終ジャッジ日時 | 2024-11-16 20:01:47 |
| 合計ジャッジ時間 | 23,207 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
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();
PriorityQueue<Integer> queue = new PriorityQueue<>();
for (int i = 0; i < n; i++) {
queue.add(-sc.nextInt());
}
double[] ans = new double[500001];
TreeSet<Poll> polls = new TreeSet<>();
ans[1] = -queue.poll();
polls.add(new Poll(polls.size(), ans[1], 2));
for (int i = 2; i <= 500000; i++) {
if (queue.size() == 0 || polls.last().value() > -queue.peek()) {
Poll p = polls.pollLast();
ans[i] = p.value();
p.add();
polls.add(p);
} else {
ans[i] = -queue.poll();
polls.add(new Poll(polls.size(), ans[i], 2));
}
}
int q = sc.nextInt();
StringBuilder sb = new StringBuilder();
while (q-- > 0) {
sb.append(new java.math.BigDecimal(ans[sc.nextInt()]).toPlainString()).append("\n");
}
System.out.print(sb);
}
static class Poll implements Comparable<Poll> {
int idx;
double current;
int size;
public Poll(int idx, double current, int size) {
this.idx = idx;
this.current = current;
this.size = size;
}
public double value() {
return current / size;
}
public void add() {
size++;
}
public int compareTo(Poll another) {
if (value() == another.value()) {
return idx - another.idx;
} else if (value() < another.value()) {
return -1;
} else {
return 1;
}
}
public int hashCode() {
return idx;
}
public boolean equals(Object o) {
return hashCode() == o.hashCode();
}
}
}
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