結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー hang_hang_cln
提出日時 2018-06-14 23:01:27
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,017 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 68,544 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-03-03 11:15:30
合計ジャッジ時間 4,695 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

long long sticks[200005];
int countCuttedSticks(double cutLength) {
    int count = 0;
    for (int stick: sticks) {
        count += (long long)((double) stick / cutLength);
    }

    return count;
}

int main(void){
    // Your code here!
    int N;
    cin >> N;
    for (int i=0; i < N; i++) {
        cin>>sticks[i];
    }
    long long K;
    cin>>K;

    double high, low, ans;
    long long max = 0;
    for (int i=0; i < N; i++) {
        if (max < sticks[i])
            max = sticks[i];
    }
    high = (double)max;
    low = 0.0;

    if (countCuttedSticks(high) == K)
        cout << high << endl;
    else {
        for(int i = 0; i < 100; i++) {
            ans = (high + low) / 2.0;
            if (countCuttedSticks(ans) >= K)
                low = ans;
            else
                high = ans;
        }
        cout<<fixed;
        cout << setprecision(10)<<ans<< endl;
    }
    return 0;
}
0