結果

問題 No.306 さいたま2008
コンテスト
ユーザー forest3
提出日時 2025-03-26 16:45:30
言語 C++14
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 725 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,010 ms
コンパイル使用メモリ 184,744 KB
実行使用メモリ 9,284 KB
最終ジャッジ日時 2026-07-07 23:01:16
合計ジャッジ時間 2,730 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
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/istream:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/sstream:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/complex:50,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/ccomplex:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:133,
                 from main.cpp:1:
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:31:39:
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/ostream.h:244:25: warning: 'y' may be used uninitialized [-Wmaybe-uninitialized]
  244 |       { return _M_insert(__f); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:10:52: note: 'y' was declared here
   10 |         long double l = -1, h = 1e18, t = DBL_MAX, y;
      |                                                    ^

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
	ll xa, ya, xb, yb;
	cin >> xa >> ya >> xb >> yb;
	long double l = -1, h = 1e18, t = DBL_MAX, y;
	rep(i, 200) {
		long double e1 = (l + l + h) / 3;
		long double e2 = (l + h + h) / 3;
		long double dy1 = e1 - ya;
		long double dy2 = e1 - yb;
		long double f1 = sqrt(xa * xa + dy1 * dy1) + sqrt(xb * xb + dy2 * dy2);
		dy1 = e2 - ya;
		dy2 = e2 - yb;
		long double f2 = sqrt(xa * xa + dy1 * dy1) + sqrt(xb * xb + dy2 * dy2);
		if(f1 < f2) h = e2;
		else l = e1;
		if(f1 < t) {
			t = f1;
			y = e1;
		}
		if(f2 < t) {
			t = f2;
			y = e2;
		}
	}
	cout << fixed << setprecision(12) << y << endl;
}
0