結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー task4233task4233
提出日時 2019-01-01 14:41:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,142 bytes
コンパイル時間 1,795 ms
コンパイル使用メモリ 166,152 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2024-04-24 20:04:32
合計ジャッジ時間 9,405 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 228 ms
9,728 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 199 ms
9,728 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 222 ms
9,856 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 173 ms
8,832 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 188 ms
8,832 KB
testcase_16 AC 199 ms
9,856 KB
testcase_17 AC 199 ms
9,728 KB
testcase_18 AC 199 ms
9,856 KB
testcase_19 AC 221 ms
9,728 KB
testcase_20 AC 220 ms
9,728 KB
testcase_21 AC 221 ms
9,728 KB
testcase_22 AC 179 ms
8,960 KB
testcase_23 AC 191 ms
9,728 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 3 ms
5,376 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n;
  vector< long double > l(n);
  for (int i=0; i<n; ++i) cin >> l[i];
  cin >> k;
  
  auto check = [=](long double mid) {
    long double sm = 0;
    for (int i=0; i<n; ++i)
      // long doubleなので, 値を潰さないように
      sm += (floor)(l[i] / mid);
    return sm >= k;
  };
  
  // [ok, ng) okはギリギリ満たす数, ngがギリギリ満たさない数
  // そのうち, 満たす数の最大値を求めたい
  // ただし, 今回は小数が答えなので範囲を狭めることで解を求める
  // 1度二分探索をすると, 解の範囲は(1/2)になるので, 
  // 10^10の範囲を10^-9以下(怖いので10^-10未満にします)にするためには, 
  // log2(n) = (10^10)/(10^10) = 10^20を解いて, 大体n >= 67くらい?
  // まぁ100回も回せば十分でしょう
  long double ok = 0, ng = 1e10 + 1;
  for (int i=0; i<100; ++i) {
    long double mid = (ng+ok)/2;
    if (check(mid)) ok = mid;
    else ng = mid;
  }
  double ans = ok;
  cout << fixed << setprecision(10) << ans << endl;
  
  return 0;
}
0