結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
5,104 KB
testcase_01 AC 133 ms
4,376 KB
testcase_02 AC 160 ms
4,380 KB
testcase_03 AC 186 ms
4,640 KB
testcase_04 AC 186 ms
5,056 KB
testcase_05 AC 186 ms
5,224 KB
testcase_06 AC 186 ms
5,232 KB
testcase_07 AC 207 ms
5,072 KB
testcase_08 AC 207 ms
5,104 KB
testcase_09 AC 206 ms
5,080 KB
testcase_10 AC 180 ms
5,068 KB
testcase_11 AC 183 ms
4,944 KB
testcase_12 AC 179 ms
5,020 KB
testcase_13 AC 201 ms
5,160 KB
testcase_14 AC 204 ms
5,124 KB
testcase_15 AC 196 ms
4,988 KB
testcase_16 AC 186 ms
5,080 KB
testcase_17 AC 186 ms
5,080 KB
testcase_18 AC 186 ms
5,080 KB
testcase_19 AC 207 ms
5,060 KB
testcase_20 AC 207 ms
5,100 KB
testcase_21 AC 207 ms
5,020 KB
testcase_22 WA -
testcase_23 AC 184 ms
5,156 KB
testcase_24 AC 131 ms
4,380 KB
testcase_25 AC 133 ms
4,376 KB
testcase_26 AC 131 ms
4,376 KB
testcase_27 AC 132 ms
4,380 KB
testcase_28 AC 144 ms
4,380 KB
testcase_29 AC 137 ms
4,380 KB
testcase_30 AC 133 ms
4,380 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 (K == 1)
        cout << high << endl;
    else 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