結果

問題 No.68 よくある棒を切る問題 (2)
ユーザー koyumeishikoyumeishi
提出日時 2014-11-17 01:13:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 240 ms / 5,000 ms
コード長 1,476 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 82,568 KB
実行使用メモリ 10,116 KB
最終ジャッジ日時 2023-08-30 08:49:13
合計ジャッジ時間 10,435 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 239 ms
9,984 KB
testcase_01 AC 240 ms
9,916 KB
testcase_02 AC 240 ms
9,968 KB
testcase_03 AC 229 ms
9,772 KB
testcase_04 AC 229 ms
9,760 KB
testcase_05 AC 229 ms
10,116 KB
testcase_06 AC 232 ms
9,244 KB
testcase_07 AC 237 ms
9,508 KB
testcase_08 AC 221 ms
9,268 KB
testcase_09 AC 225 ms
9,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//提出#2751に書いてある個人用メモは嘘です気にしないでくださいごめんなさい

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> l(n);
	for(int i=0; i<n; i++) scanf("%d", &l[i]);
	int Q;
	cin >> Q;
	vector<int> k(Q);
	for(int i=0; i<Q; i++) scanf("%d", &k[i]);

	priority_queue< pair<double, int> > pq;
	for(int i=0; i<n; i++) pq.push( make_pair(l[i], i) );

	int m = *max_element(k.begin(), k.end());

	//ans[i] := i個切り出したときの最大の長さ
	vector<double> ans(m+1);

	//cut[i] := i番目の棒をいくつにカットしたか
	vector<int> cut(n,1);
	
	for(int i=1; i<=m; ++i){
		//更に1つ切り出そうとした場合に一番長く切り出せる棒
		pair<double, int> p = pq.top();
		pq.pop();
		double L = p.first;
		int id = p.second;

		//i個にカットすると最大の長さはLとなる
		ans[i] = L;
		
		//cut[id]個に切られている棒を更に切って(cut[id]+1)個切り出したい
		cut[id] += 1;

		//棒[id]から(cut[id]+1)個取り出すとした場合の長さは
		//l[id] / (cut[id]+1)
		pq.push( make_pair( l[id]/(double)(cut[id]), id ) );
		
	}

	//よくわからんぽよ

	for(int i=0; i<Q; i++){
		printf("%.10f\n", ans[ k[i] ]);
	}
	return 0;
}
0