結果

問題 No.180 美しいWhitespace (2)
ユーザー antaanta
提出日時 2015-04-06 00:03:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,240 ms / 5,000 ms
コード長 2,104 bytes
コンパイル時間 1,232 ms
コンパイル使用メモリ 88,908 KB
実行使用メモリ 13,152 KB
最終ジャッジ日時 2023-09-17 04:49:51
合計ジャッジ時間 7,430 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 14 ms
4,380 KB
testcase_06 AC 45 ms
4,380 KB
testcase_07 AC 92 ms
5,112 KB
testcase_08 AC 164 ms
5,136 KB
testcase_09 AC 40 ms
7,936 KB
testcase_10 AC 41 ms
8,016 KB
testcase_11 AC 1,125 ms
12,040 KB
testcase_12 AC 1,240 ms
12,496 KB
testcase_13 AC 939 ms
11,680 KB
testcase_14 AC 466 ms
11,564 KB
testcase_15 AC 211 ms
13,152 KB
testcase_16 AC 134 ms
11,956 KB
testcase_17 AC 97 ms
11,724 KB
testcase_18 AC 75 ms
11,708 KB
testcase_19 AC 49 ms
8,240 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 49 ms
11,728 KB
testcase_31 AC 49 ms
11,912 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 26 ms
8,988 KB
testcase_34 AC 25 ms
7,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N;
	scanf("%d", &N);
	vector<int> a(N), b(N);
	rep(i, N) scanf("%d%d", &a[i], &b[i]);
	vpii bis(N);
	rep(i, N) bis[i] = mp(b[i], i);
	sort(all(bis));
	vi candidates;
	candidates.push_back(1);
	rep(i, N) rep(j, N) {
//		int i = bis[ix].second, j = bis[ix+1].second;
		if(b[i] == b[j]) continue;
		//b_i x + a_i = b_j x + a_j
		//x = (a_j - a_i) / (b_i - b_j)
		int t = a[i] - a[j], u = b[j] - b[i];
		if(u < 0) t *= -1, u *= -1;
		if(t < 0) continue;
		if(t / u > 0) candidates.push_back(t / u);
		candidates.push_back(t / u + 1);
	}
	sort(all(candidates));
	candidates.erase(unique(all(candidates)), candidates.end());
	pair<ll,int> ans(INFL,-1);
	each(xi, candidates) {
		int x = *xi;
		ll ma = 0, mi = INFL;
		rep(i, N) {
			ll t = a[i] + (ll)b[i] * x;
			amax(ma, t);
			amin(mi, t);
		}
//		cerr << x << ": "<< ma << ", " << mi << endl;
		amin(ans, mp(ma - mi, x));
	}
	printf("%d\n", ans.second);
	return 0;
}
0