結果

問題 No.180 美しいWhitespace (2)
ユーザー Lay_ecLay_ec
提出日時 2015-04-06 00:39:51
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,614 bytes
コンパイル時間 652 ms
コンパイル使用メモリ 88,112 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-17 05:28:02
合計ジャッジ時間 2,368 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>

using namespace std;

int n;
unsigned long long a[1001],b[1001];


unsigned long long f(unsigned long long x)
{
	unsigned long long _max=a[0]+b[0]*x,_min=a[0]+b[0]*x;

	for(int i=1;i<n;i++){
		_max=max(_max,a[i]+b[i]*x);
		_min=min(_min,a[i]+b[i]*x);
	}

	return _max-_min;
}

//下に凸
unsigned long long f2(unsigned long long x)
{
	return f(x)*f(x);
}

// left-ml-mr-right
unsigned long long search(unsigned long long left, unsigned long long right)
{
	for (long long i = 0; i < 10000; i++){
		unsigned long long ml=(right-left)/3,mr=2*(right-left)/3;
		unsigned long long fl=f2(ml),fr=f2(mr);
		if(fl>fr) left=ml;
		else right=mr;
	}
	return (right + left)/2;
}

int main()
{
	cin>>n;

	set<pair<unsigned long long,unsigned long long> > s;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		s.insert(make_pair(a[i],b[i]));
	}

	if(s.size()==1){cout<<1<<endl; return 0;}

	unsigned long long left=1,right=1e6;
	unsigned long long mid=search(left,right);
//	cout<<mid<<endl;

	vector<pair<unsigned long long,unsigned long long> > vp;
	vp.push_back(make_pair(f(mid-2),mid-2));
	vp.push_back(make_pair(f(mid-1),mid-1));
	vp.push_back(make_pair(f(mid),mid));
	vp.push_back(make_pair(f(mid+1),mid+1));
	vp.push_back(make_pair(f(mid+2),mid+2));

	sort(vp.begin(),vp.end());
	for(int i=0;i<5;i++){
		if(vp[i].second>0){ cout<<vp[i].second<<endl; break;}
	}

	return 0;
}
0