結果
| 問題 |
No.67 よくある棒を切る問題 (1)
|
| コンテスト | |
| ユーザー |
hang_hang_cln
|
| 提出日時 | 2018-06-14 22:22:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 918 bytes |
| コンパイル時間 | 544 ms |
| コンパイル使用メモリ | 67,776 KB |
| 実行使用メモリ | 13,180 KB |
| 最終ジャッジ日時 | 2025-03-03 11:15:24 |
| 合計ジャッジ時間 | 9,173 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 15 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:41:17:
/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:26:23: note: ‘ans’ was declared here
26 | double high, low, ans;
| ^~~
ソースコード
#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;
}
}
hang_hang_cln