結果
| 問題 | 
                            No.67 よくある棒を切る問題 (1)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             hang_hang_cln
                         | 
                    
| 提出日時 | 2018-06-14 22:32:25 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 985 bytes | 
| コンパイル時間 | 1,118 ms | 
| コンパイル使用メモリ | 83,040 KB | 
| 実行使用メモリ | 8,608 KB | 
| 最終ジャッジ日時 | 2025-03-03 11:15:29 | 
| 合計ジャッジ時間 | 9,687 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 5 WA * 11 TLE * 1 -- * 13 | 
コンパイルメッセージ
In file included from /usr/include/c++/13/iostream:41,
                 from main.cpp:1:
In member function ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>]’,
    inlined from ‘int main()’ at main.cpp:42:35:
/usr/include/c++/13/ostream:223:25: warning: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
  223 |       { return _M_insert(__f); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function ‘int main()’:
main.cpp:27:23: note: ‘ans’ was declared here
   27 |     double high, low, ans;
      |                       ^~~
            
            ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
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 = (double)*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.0;
            if (countCuttedSticks(sticks, ans) >= K)
                low = ans;
            else
                high = ans;
        }
        cout<<fixed;
        cout << setprecision(10)<<ans<< endl;
    }
    return 0;
}
            
            
            
        
            
hang_hang_cln