結果

問題 No.68 よくある棒を切る問題 (2)
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-02-18 21:42:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 440 ms / 5,000 ms
コード長 1,736 bytes
コンパイル時間 2,906 ms
コンパイル使用メモリ 174,044 KB
実行使用メモリ 12,140 KB
最終ジャッジ日時 2023-10-23 18:12:48
合計ジャッジ時間 15,052 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 438 ms
12,140 KB
testcase_01 AC 433 ms
12,140 KB
testcase_02 AC 431 ms
12,140 KB
testcase_03 AC 431 ms
12,140 KB
testcase_04 AC 440 ms
12,140 KB
testcase_05 AC 431 ms
12,140 KB
testcase_06 AC 421 ms
11,300 KB
testcase_07 AC 427 ms
11,724 KB
testcase_08 AC 414 ms
11,188 KB
testcase_09 AC 418 ms
11,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define whole(xs) (xs).begin(),(xs).end()

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    vector<real> L;
    int Q;
    vector<ll> K;
    void input() {
        cin >> N; L.resize(N); cin >> L;
        cin >> Q; K.resize(Q); cin >> K;
    }

    struct S {
        real nlen;
        int index;
        S(real nlen, int index) : nlen(nlen), index(index) {}
    };
    bool operator<(const S& a, const S& b) {
        return a.nlen < b.nlen;
    }

    void solve() {
        vector<ll> K2 = K;
        sort(whole(K2));

        vector<real> X(N, 0);
        ll count = 0;
        priority_queue<S> PQ;
        for (int i = 0; i < N; i++) {
            PQ.push(S(L[i], i));
        }
        vector<real> ans(K2[Q - 1] + 5, -1);
        while (count <= K2[Q - 1] && not PQ.empty()) {
            S cur = PQ.top(); PQ.pop();
            //cout << cur.index << " " << cur.nlen << endl;
            int i = cur.index;
            real next = cur.nlen;
            X[i]++;
            ans[++count] = next;
            PQ.push(S( L[i] / (X[i] + 1), i ));
        }
        cout << setprecision(15);
        for (int i = 0; i < Q; i++) {
            cout << ans[ K[i] ] << endl;
        }
    }
}

int main() {
    input(); solve();
    return 0;
}

0