結果

問題 No.68 よくある棒を切る問題 (2)
ユーザー not_522not_522
提出日時 2015-08-17 20:28:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 573 ms / 5,000 ms
コード長 967 bytes
コンパイル時間 1,371 ms
コンパイル使用メモリ 153,876 KB
実行使用メモリ 13,664 KB
最終ジャッジ日時 2023-09-25 12:37:06
合計ジャッジ時間 14,848 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 558 ms
11,980 KB
testcase_01 AC 559 ms
12,268 KB
testcase_02 AC 572 ms
12,308 KB
testcase_03 AC 573 ms
11,952 KB
testcase_04 AC 554 ms
12,316 KB
testcase_05 AC 562 ms
12,540 KB
testcase_06 AC 531 ms
13,664 KB
testcase_07 AC 536 ms
13,040 KB
testcase_08 AC 514 ms
11,780 KB
testcase_09 AC 536 ms
12,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

template<typename Function> long double bisectionMethod(Function function, long double lower, long double upper) {
  for (int i = 0; i < 200; ++i) {
    long double middle = (lower + upper) / 2;
    (function(middle) <= 0 ? lower : upper) = middle;
  }
  return lower;
}

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int& i : l) cin >> i;
  auto f = [&](double x){
    long long sum = 0;
    for (int& i : l) sum += floor(i / x);
    return sum - 500000 + 0.5;
  };
  auto mx =  bisectionMethod(f, numeric_limits<int>::max(), 0);
  vector<long double> res;
  for (const int& i : l) {
    for (int j = 1; ; ++j) {
      long double d = (long double)i / j;
      if (d < mx - 1e-9) break;
      res.emplace_back(d);
    }
  }
  sort(res.rbegin(), res.rend());
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int k;
    cin >> k;
    cout << fixed << setprecision(15) << res[k - 1] << endl;
  }
}
0