結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー vrjfsyi
提出日時 2018-04-02 07:59:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 130 ms / 5,000 ms
コード長 771 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 70,868 KB
実行使用メモリ 8,608 KB
最終ジャッジ日時 2025-03-03 11:10:35
合計ジャッジ時間 4,499 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <array>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;

long ls[200000];

long f(double x, int N) {
    long count = 0;
    for (int i = 0; i < N; ++i) {
        count += (long) (ls[i] / x);
    }
    return count;
}


int main() {

    int N;
    cin >> N;


    long L;
    for (int i = 0; i < N; ++i) {
        cin >> L;
        ls[i] = L;
    }

    long K;
    cin >> K;

    double a = 0;
    double b = 1000000000;

    double x;
    for (int j = 0; j < 100; ++j) {

        x = (a + b) / 2;

        if (f(x, N) >= K) {
            a = x;
        } else {
            b = x;
        }
    }

    printf("%.14f\n", x);

    return 0;
}

0