結果
問題 | No.68 よくある棒を切る問題 (2) |
ユーザー |
|
提出日時 | 2021-04-23 17:50:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,201 ms / 5,000 ms |
コード長 | 1,848 bytes |
コンパイル時間 | 2,241 ms |
コンパイル使用メモリ | 200,240 KB |
最終ジャッジ日時 | 2025-01-20 23:23:19 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
#include <bits/stdc++.h>using namespace std;using int128 = __int128_t;#define rep(i, n) for (int i = 0; i < n; ++i)#define reps(i, n, s) for (int i = 0; i < n; i += s)#define repl(i, l, r) for (int i = l; i < r; ++i)#define repsl(i, l, r, s) for (int i = l; i < r; i += s)#define all(iterable) (iterable).begin(), (iterable).end()constexpr int dx4[4] = {1, 0, -1, 0};constexpr int dy4[4] = {0, 1, 0, -1};constexpr int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};constexpr int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};template <typename T>void print_vector(const vector<T>& vec, const string sep = " ", const string end = "\n") {int n = vec.size();rep(i, n) {cout << vec[i];if (i < n - 1) cout << sep;else cout << end;}}template <typename T>void read_vector(vector<T>& a, int begin_index, int length) {if (a.size() < begin_index + length) a.resize(begin_index + length);while (length --> 0) cin >> a[begin_index++];}template <typename T>void read_vector(vector<T>& a) { read_vector(a, 0, a.size()); }constexpr size_t M = 500010;int main() {size_t n;cin >> n;vector<size_t> l(n), t(n, 0);read_vector(l, 0, n);auto cmp = [&](size_t x, size_t y) {long double xd = (long double) l[x] / (t[x] + 1);long double yd = (long double) l[y] / (t[y] + 1);return xd < yd;};priority_queue<size_t, vector<size_t>, decltype(cmp)> pq {cmp};rep(j, n) pq.push(j);vector<long double> ans(M);repl(i, 1, M) {size_t j = pq.top();pq.pop();ans[i] = (long double) l[j] / ++t[j];pq.push(j);}size_t q;cin >> q;cout << fixed << setprecision(20);while (q --> 0) {size_t k;cin >> k;cout << ans[k] << '\n';}return 0;}