結果

問題 No.180 美しいWhitespace (2)
ユーザー ty70ty70
提出日時 2015-04-06 15:49:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,180 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 92,660 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-17 06:12:16
合計ジャッジ時間 1,817 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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))
#define INF (ll)1e8
#define INF2 1LL<<60

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

ll fx (vector<int> a, vector<int> b, ll x ){
	int n = a.size();
	ll maxs = 0LL;
	ll mins = INF;
	rep (i, n ){
		maxs = max (maxs, (ll)a[i] + x*(ll)b[i] );
		mins = min (mins, (ll)a[i] + x*(ll)b[i] );
	} // end rep
	
	return (maxs - mins );
}
	
int main()
{
	ios_base::sync_with_stdio(0);
	int N; cin >> N;
	vector<int> a(N, 0 ), b (N, 0 );
	rep (i, N ){
		cin >> a[i] >> b[i];
	} // end rep
	ll lo = 1LL;
	ll hi = INF;
	ll res = 0LL;
	int cnt = 1000;
	while (cnt-- ){
		ll cl = lo + (hi - lo)/3LL;
		ll cr = lo + 2LL*(hi - lo)/3LL;
		if (fx(a,b,cl) < fx(a,b,cr ) ){
			res = cl;
			hi = cr;
		}else
		if (fx (a, b, cl ) > fx(a, b, cr ) ){
			res = cr;
			lo = cl;
		}else{
			res = cl;
			break;
		} // end if	
	} // end while
	if (cnt == 999 ) hi = lo;
//	cerr << "lo: " << lo << " hi: " << hi << endl;
	ll curr = INF2;
	for (ll x = lo;x <= hi; x++ ){
		if (curr >= fx(a,b,x ) ){
			res = x;
			curr = fx(a,b,x );
		} // end if
	} // end for
	
	cout << res << endl;

	return 0;
}
0