結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー kyunakyuna
提出日時 2019-08-11 02:58:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 220 ms / 5,000 ms
コード長 744 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 79,024 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 00:45:06
合計ジャッジ時間 6,759 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 220 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 82 ms
6,944 KB
testcase_03 AC 155 ms
6,940 KB
testcase_04 AC 189 ms
6,944 KB
testcase_05 AC 191 ms
6,940 KB
testcase_06 AC 189 ms
6,940 KB
testcase_07 AC 213 ms
6,940 KB
testcase_08 AC 213 ms
6,944 KB
testcase_09 AC 213 ms
6,940 KB
testcase_10 AC 171 ms
6,940 KB
testcase_11 AC 180 ms
6,940 KB
testcase_12 AC 164 ms
6,944 KB
testcase_13 AC 196 ms
6,940 KB
testcase_14 AC 204 ms
6,940 KB
testcase_15 AC 183 ms
6,944 KB
testcase_16 AC 191 ms
6,940 KB
testcase_17 AC 190 ms
6,940 KB
testcase_18 AC 189 ms
6,944 KB
testcase_19 AC 213 ms
6,944 KB
testcase_20 AC 213 ms
6,944 KB
testcase_21 AC 214 ms
6,940 KB
testcase_22 AC 171 ms
6,944 KB
testcase_23 AC 180 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 6 ms
6,944 KB
testcase_26 AC 3 ms
6,944 KB
testcase_27 AC 3 ms
6,940 KB
testcase_28 AC 36 ms
6,940 KB
testcase_29 AC 18 ms
6,944 KB
testcase_30 AC 6 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
using ll = long long;

vector<int> ls;
ll k;

bool check(double x) {
    ll cnt = 0;
    for (int l: ls) cnt += l / x;
    return cnt >= k;
}

double binary_search(double ok, double ng) {
    // assert(check(ok) == true);
    // assert(check(ng) == false);
    for (int i = 0; i < 100; i++) {
        double mid = (ng + ok) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    return ok;
}

#include <iomanip>
int main() {
    cout << fixed << setprecision(12);
    int n; cin >> n;
    ls.resize(n);
    for (int &l: ls) cin >> l;
    cin >> k;
    double ok = 0;
    double ng = 1e12;
    cout << binary_search(ok, ng) << endl;
    return 0;
}
0