結果
| 問題 | No.67 よくある棒を切る問題 (1) |
| コンテスト | |
| ユーザー |
hang_hang_cln
|
| 提出日時 | 2018-06-14 22:32:25 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 985 bytes |
| 記録 | |
| コンパイル時間 | 580 ms |
| コンパイル使用メモリ | 103,012 KB |
| 実行使用メモリ | 10,856 KB |
| 最終ジャッジ日時 | 2026-07-06 17:29:53 |
| 合計ジャッジ時間 | 8,811 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 11 TLE * 1 -- * 13 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/ostream:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/iostream:43,
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:
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/ostream.h:232:25: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
232 | { 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