結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー hang_hang_clnhang_hang_cln
提出日時 2018-06-14 23:09:42
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,051 bytes
コンパイル時間 511 ms
コンパイル使用メモリ 67,480 KB
実行使用メモリ 5,228 KB
最終ジャッジ日時 2023-09-13 04:21:51
合計ジャッジ時間 7,581 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 213 ms
5,112 KB
testcase_01 AC 131 ms
4,376 KB
testcase_02 AC 160 ms
4,376 KB
testcase_03 AC 186 ms
4,700 KB
testcase_04 AC 186 ms
5,228 KB
testcase_05 AC 185 ms
5,008 KB
testcase_06 AC 185 ms
5,012 KB
testcase_07 AC 207 ms
4,952 KB
testcase_08 AC 207 ms
5,044 KB
testcase_09 AC 206 ms
5,184 KB
testcase_10 AC 180 ms
4,992 KB
testcase_11 AC 183 ms
5,068 KB
testcase_12 AC 179 ms
4,812 KB
testcase_13 AC 201 ms
5,088 KB
testcase_14 AC 202 ms
4,932 KB
testcase_15 AC 194 ms
5,000 KB
testcase_16 AC 185 ms
5,012 KB
testcase_17 AC 186 ms
5,036 KB
testcase_18 AC 186 ms
5,220 KB
testcase_19 AC 207 ms
5,012 KB
testcase_20 AC 206 ms
5,004 KB
testcase_21 AC 207 ms
5,040 KB
testcase_22 WA -
testcase_23 AC 185 ms
5,144 KB
testcase_24 AC 131 ms
4,376 KB
testcase_25 AC 133 ms
4,380 KB
testcase_26 AC 131 ms
4,376 KB
testcase_27 AC 131 ms
4,380 KB
testcase_28 AC 144 ms
4,376 KB
testcase_29 AC 137 ms
4,376 KB
testcase_30 AC 133 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long sticks[200005];
long long countCuttedSticks(double cutLength) {
    long long count = 0;
    for (int stick: sticks) {
        count +=  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<<high<<","<<low<<endl;
        }
        cout<<fixed;
        cout << setprecision(11)<<ans<< endl;
    }
    return 0;
}
0