結果

問題 No.180 美しいWhitespace (2)
ユーザー ty70ty70
提出日時 2015-04-14 16:06:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,994 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 91,096 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 20:16:24
合計ジャッジ時間 1,959 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,384 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define each(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizoef(a))
#define sz(s) (int)((s).size())
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define pb push_back
#define MP(x,y) make_pair((x),(y))

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
vector<ll> a, b;

ll fx(int n, ll x ){
	ll maxv = 0LL;
	ll minv = 1LL<<60;
	rep (i, n ){
		ll v = a[i] + b[i]*x;
		maxv = max (maxv, v );
		minv = min (minv, v );
	} // end rep

	return (maxv - minv );
}
int main()
{
	ios_base::sync_with_stdio(0);
	int N; cin >> N;
	a.clear(); a.resize(N, 0LL );
	b.clear(); b.resize(N, 0LL );

	rep (i, N ) cin >> a[i] >> b[i];

	ll lo = 1LL;
	ll hi = 1LL<<30;
	ll res = 1LL;
	while (lo <= hi && (hi - lo ) > 3LL ){
		ll cl = lo + (hi - lo )/3LL;
		ll cr = hi - (hi - lo )/3LL;
		ll suml = fx (N, cl );
		ll sumr = fx (N, cr );
		if (suml <= sumr ){
			hi = cr;
		}else{
			lo = cl;
		} // end if
	} // end while

	ll curr = 1LL<<60;
	for (ll x = lo; x <= hi; x++ ){
		ll sum = fx (N, x );
		if (curr > sum ){
			res = x;
			curr = sum;
		} // end if
	} // end for

	cout << res << endl;

	return 0;
}
0