結果
問題 | No.67 よくある棒を切る問題 (1) |
ユーザー |
![]() |
提出日時 | 2018-06-14 22:32:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 985 bytes |
コンパイル時間 | 711 ms |
コンパイル使用メモリ | 84,640 KB |
実行使用メモリ | 4,928 KB |
最終ジャッジ日時 | 2023-09-13 04:19:23 |
合計ジャッジ時間 | 9,917 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 100 ms
4,892 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 77 ms
4,728 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 98 ms
4,900 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 67 ms
4,376 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 83 ms
4,376 KB |
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 | -- | - |
コンパイルメッセージ
次のファイルから読み込み: /usr/local/gcc7/include/c++/12.2.0/iostream:39, 次から読み込み: main.cpp:1: メンバ関数 ‘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/local/gcc7/include/c++/12.2.0/ostream:221:25: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized] 221 | { return _M_insert(__f); } | ~~~~~~~~~^~~~~ main.cpp: 関数 ‘int main()’ 内: main.cpp:27:23: 備考: ‘ans’ はここで定義されています 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; }