結果

問題 No.180 美しいWhitespace (2)
コンテスト
ユーザー omu
提出日時 2015-04-07 09:31:40
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,774 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 620 ms
コンパイル使用メモリ 107,196 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-25 12:11:11
合計ジャッジ時間 3,554 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17 WA * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/string:53,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/locale_classes.h:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ios_base.h:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ios:46,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
                 from main.cpp:3:
In function 'const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = long long int]',
    inlined from 'int main()' at main.cpp:90:13:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:239:7: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
  239 |       if (__b < __a)
      |       ^~
main.cpp: In function 'int main()':
main.cpp:82:12: note: 'ans' was declared here
   82 |         ll ans; ll Min = 1e18;
      |            ^~~

ソースコード

diff #
raw source code

#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <list>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

#define rep(i,n)  for(int (i) = 0;(i) < (n);(i)++)
#define clr(a) memset((a), 0 ,sizeof(a))
#define mclr(a) memset((a), -1 ,sizeof(a))
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) (sizeof(a))
#define Fill(a,v) fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)
bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 2147483647;

ll n;
ll a[1010], b[1010];

ll solve(double x){
	ll Max = 0,Min = INF;
	rep(i, n){
		ll v = a[i] + b[i]*x;
		Max = max(v,Max);
		Min = min(v,Min);
	}
	return Max - Min;
}

int main()
{
	cin >> n;
	rep(i, n){
		cin >> a[i] >> b[i];
	}


	ll l=1,r=INF;
	ll m1,m2;

	while(1){

		m1 = (2*l+r)/3;
		m2 = (2*r+l)/3;

		ll m1v = solve(m1);
		ll m2v = solve(m2);

		if (m1v > m2v){
			l = m1;
		}else
		{
			r = m2;
		}


		if (abs(l-r) < 100000)
			break;

	}

	ll ans; ll Min = 1e18;
	for (ll i = l; i <= r; i++){
		ll t = solve(i);
		if (t < Min){
			Min = t;
			ans = i;
		}
		if (t == Min){
			ans = min(i,ans);
		}
	}

	cout << ans << endl;
	return 0;
}
0