結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
4,836 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int countCuttedSticks(vector<int> sticks, double cutLength) {
    int count = 0;
    for (int stick: sticks) {
        count += (int)((double) stick / cutLength);
    }
    
    return count;
}

int main(void){
    // Your code here!
    int N;
    cin >> N;
    vector<int> sticks(N);
    for (int i=0; i < N; i++) {
        cin>>sticks[i];
    }
    long long K;
    cin>>K;
    
    double high, low, ans;
    high = *max_element(sticks.begin(), sticks.end());
    low = 0.0;
    
    if (countCuttedSticks(sticks, high) == K)
        cout << high << endl;
    else {
        while(high - low >= 0.0000000002) {
            ans = (high + low) / 2;
            if (countCuttedSticks(sticks, ans) >= K)
                low = ans;
            else
                high = ans;
        }
        
        cout << ans << endl;
    }
    
}
0