結果

問題 No.68 よくある棒を切る問題 (2)
ユーザー keikei
提出日時 2018-04-24 00:05:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 511 ms / 5,000 ms
コード長 2,575 bytes
コンパイル時間 1,649 ms
コンパイル使用メモリ 172,576 KB
実行使用メモリ 16,172 KB
最終ジャッジ日時 2023-09-09 21:41:29
合計ジャッジ時間 15,470 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 505 ms
16,172 KB
testcase_01 AC 510 ms
15,580 KB
testcase_02 AC 511 ms
15,860 KB
testcase_03 AC 492 ms
15,512 KB
testcase_04 AC 506 ms
15,436 KB
testcase_05 AC 487 ms
15,672 KB
testcase_06 AC 493 ms
15,616 KB
testcase_07 AC 506 ms
15,100 KB
testcase_08 AC 459 ms
14,744 KB
testcase_09 AC 482 ms
15,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://yukicoder.me/problems/no/68>
 問題文============================================================
 ユウキさんは N 本の棒を持っていて、i 番目の棒の長さは Li です。
 棒は(長さを分割する方向に)自由に切ることができますが、繋げることはできません。
 ユウキさんは同じ長さの棒を作りたいのですが、何本であればどのぐらいの長さにできるかが気になっています。
 同じ長さの棒を K1,K2,…,KQ 本作るとしたら、その時の棒の長さの最大値をそれぞれ求めるプログラムを書いて下さい。
 =================================================================
 解説=============================================================
 ================================================================
 */

typedef long double ld;
#define MAX_K 500001
ld query[MAX_K];

struct bou{
    ld L;
    ll x;
    bou(){}
    bou(ld l,ll x):L(l),x(x){}
    bool operator < (const bou& b) const{
        return (L/(x+1)) < (b.L/(b.x+1));
    }
};
void solve(){
    ll N; cin >> N;
    priority_queue<bou> pq;
    vector<ll> L(N); for(auto& in:L){ cin >> in; pq.push(bou(in,0)); }
    for(int i = 1; i < MAX_K; i++){
        auto b = pq.top(); pq.pop();
       // cout << b.L << " " << b.x << endl;
        b.x++;
        query[i] = b.L/b.x;
        pq.push(b);
    }
    ll Q; cin >> Q;
    vector<ll> K(Q); for(auto& in:K){
        cin >> in;
        cout << fixed << setprecision(12) <<  query[in] << endl;
    }
    
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}
0