結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
5,296 KB
testcase_01 AC 132 ms
4,380 KB
testcase_02 AC 159 ms
4,380 KB
testcase_03 AC 186 ms
4,604 KB
testcase_04 AC 185 ms
5,032 KB
testcase_05 AC 185 ms
5,108 KB
testcase_06 AC 186 ms
5,088 KB
testcase_07 AC 207 ms
5,088 KB
testcase_08 AC 206 ms
5,240 KB
testcase_09 AC 206 ms
5,092 KB
testcase_10 AC 180 ms
4,952 KB
testcase_11 AC 183 ms
5,204 KB
testcase_12 AC 179 ms
5,000 KB
testcase_13 AC 200 ms
5,092 KB
testcase_14 AC 202 ms
5,036 KB
testcase_15 AC 195 ms
5,040 KB
testcase_16 AC 185 ms
5,228 KB
testcase_17 AC 186 ms
5,284 KB
testcase_18 AC 185 ms
5,092 KB
testcase_19 AC 206 ms
5,104 KB
testcase_20 AC 206 ms
5,088 KB
testcase_21 AC 207 ms
5,220 KB
testcase_22 WA -
testcase_23 AC 182 ms
5,168 KB
testcase_24 AC 131 ms
4,380 KB
testcase_25 AC 134 ms
4,376 KB
testcase_26 AC 131 ms
4,384 KB
testcase_27 AC 133 ms
4,376 KB
testcase_28 AC 143 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 (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