結果

問題 No.68 よくある棒を切る問題 (2)
ユーザー suisensuisen
提出日時 2021-04-23 17:50:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 682 ms / 5,000 ms
コード長 1,848 bytes
コンパイル時間 2,573 ms
コンパイル使用メモリ 204,940 KB
実行使用メモリ 13,380 KB
最終ジャッジ日時 2023-09-17 11:13:49
合計ジャッジ時間 19,441 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 680 ms
13,284 KB
testcase_01 AC 682 ms
13,332 KB
testcase_02 AC 682 ms
13,308 KB
testcase_03 AC 665 ms
13,360 KB
testcase_04 AC 666 ms
13,280 KB
testcase_05 AC 665 ms
13,380 KB
testcase_06 AC 659 ms
12,796 KB
testcase_07 AC 668 ms
13,192 KB
testcase_08 AC 614 ms
12,652 KB
testcase_09 AC 647 ms
12,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0