結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー SlephySlephy
提出日時 2022-05-06 17:21:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,859 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 199,856 KB
実行使用メモリ 9,160 KB
最終ジャッジ日時 2023-09-19 06:32:02
合計ジャッジ時間 15,938 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e9 + 1001010;
const ll llINF = (ll)4e18 + 11000010;
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
ll ceil(ll a, ll b){return (a+b-1) / b;};
// ================================== ここまでテンプレ ==================================

// template <typename T, typename Predicate>
// T bisection(T false_side, T true_side, Predicate pred, T tolerant = 1) {
//     assert(!is_integral_v<T> || tolerant == 1);
//     while ((false_side > true_side ? false_side - true_side : true_side - false_side) > tolerant) {
//         T mid_value = is_integral_v<T>
//             ? false_side / 2 + true_side / 2 + ("AABBC"[2 + false_side % 2 + true_side % 2] - 'B')
//             : (false_side + true_side) * 0.5;
//         (pred(mid_value) ? true_side : false_side) = mid_value;
//     }
//     return true_side;
// }
template <typename Predicate>
double bisection(double false_side, double true_side, Predicate pred, double tolerant = 1) {
    // assert(!is_integral_v<double> || tolerant == 1);
    while ((false_side > true_side ? false_side - true_side : true_side - false_side) > tolerant) {
        double mid_value = (false_side + true_side) * 0.5;
        (pred(mid_value) ? true_side : false_side) = mid_value;
    }
    return true_side;
}

int main(){
    int n; cin >> n;
    vector<double> l(n);
    for(int i = 0; i < n; i++) cin >> l[i];
    ll k; cin >> k;

    auto judge = [&](double mid) -> bool{
        if(mid <= 0) return true;
        int count = 0;
        for(int i = 0; i < n; i++){
            count += floor(l[i] / mid);
        }
        return (count >= k);
    };

    double ans = bisection(1e12, -1.0, judge, 1e-10);
    // double ans = bisection(-1.0, 1e12, judge, 1e-10);
    printf("%.12lf\n", ans);
    return 0;
}
0