結果
問題 | No.68 よくある棒を切る問題 (2) |
ユーザー | koyumeishi |
提出日時 | 2014-11-17 00:48:54 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 270 ms / 5,000 ms |
コード長 | 1,171 bytes |
コンパイル時間 | 706 ms |
コンパイル使用メモリ | 83,272 KB |
実行使用メモリ | 10,168 KB |
最終ジャッジ日時 | 2023-08-30 08:47:42 |
合計ジャッジ時間 | 9,758 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 270 ms
9,992 KB |
testcase_01 | AC | 267 ms
10,100 KB |
testcase_02 | AC | 266 ms
9,980 KB |
testcase_03 | AC | 268 ms
10,168 KB |
testcase_04 | AC | 268 ms
10,040 KB |
testcase_05 | AC | 268 ms
10,112 KB |
testcase_06 | AC | 260 ms
9,548 KB |
testcase_07 | AC | 268 ms
10,024 KB |
testcase_08 | AC | 255 ms
9,212 KB |
testcase_09 | AC | 263 ms
9,836 KB |
ソースコード
#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++) cin >> l[i]; int Q; cin >> Q; vector<int> k(Q); for(int i=0; i<Q; i++) cin >> 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()); vector<double> ans(m+1); vector<double> cut(n,1); for(int i=1; i<=m; i++){ //カット後の長さが一番長い棒 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)個にする //全体は(i+1)個の棒になる cut[id] += 1; //切った棒をpriority_queueに保管する 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; }