結果

問題 No.180 美しいWhitespace (2)
ユーザー omuomu
提出日時 2015-04-07 09:54:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,876 bytes
コンパイル時間 1,458 ms
コンパイル使用メモリ 86,840 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-17 06:33:15
合計ジャッジ時間 2,008 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 4 ms
4,384 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 4 ms
4,388 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 4 ms
4,376 KB
testcase_32 AC 4 ms
4,376 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:86:5: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  ll ans; ll Min = 1e18;
     ^~~

ソースコード

diff #

#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>
#include <fstream>

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(ll x){
	ll Max = 0,Min = 1e18;
	rep(i, n){
		ll v = a[i] + b[i]*x;
		Max = max(v,Max);
		Min = min(v,Min);
	}
	return Max - Min;
}

int main()
{
	//fstream fs("C:/Users/omu_/Desktop/425-testcase/test_in/12_randomC1.txt", ios::in);

	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) < 1000)
			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