結果

問題 No.180 美しいWhitespace (2)
ユーザー 👑 kmjpkmjp
提出日時 2015-04-06 00:24:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,751 bytes
コンパイル時間 1,285 ms
コンパイル使用メモリ 152,492 KB
実行使用メモリ 11,512 KB
最終ジャッジ日時 2023-09-17 04:56:55
合計ジャッジ時間 2,305 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,520 KB
testcase_06 AC 3 ms
7,164 KB
testcase_07 AC 3 ms
7,252 KB
testcase_08 AC 3 ms
7,464 KB
testcase_09 AC 6 ms
11,316 KB
testcase_10 AC 5 ms
11,508 KB
testcase_11 AC 6 ms
11,300 KB
testcase_12 AC 6 ms
11,264 KB
testcase_13 AC 5 ms
11,260 KB
testcase_14 AC 6 ms
11,308 KB
testcase_15 AC 6 ms
11,264 KB
testcase_16 AC 5 ms
11,364 KB
testcase_17 AC 5 ms
11,304 KB
testcase_18 AC 6 ms
11,512 KB
testcase_19 AC 6 ms
11,316 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 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,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 6 ms
11,248 KB
testcase_31 AC 7 ms
11,268 KB
testcase_32 AC 6 ms
11,372 KB
testcase_33 AC 7 ms
11,276 KB
testcase_34 AC 6 ms
11,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll X[1010],Y[1010];
ll ret;
double m=1e200;

ll val(ll x) {
	ll ma=0,mi=1LL<<60;
	int i;
	if(x<1) return 1LL<<60;
	FOR(i,N) ma=max(ma,Y[i]*x+X[i]);
	FOR(i,N) mi=min(mi,Y[i]*x+X[i]);
	
	if(ma-mi<m || (ma-mi==m && x<ret)) m=ma-mi,ret=x;
	return ma-mi;
}

double cr[1010][1010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>X[i]>>Y[i];
	
	FOR(x,N) FOR(y,N) {
		if(Y[x]==Y[y]) cr[x][y]=-1;
		else cr[x][y] = (X[y]-X[x])*1.0/(Y[x]-Y[y]);
	}
	
	set<double> S;
	S.insert(1);
	
	x=0;
	FOR(y,N) {
		if(X[y]<X[x]) x=y;
		else if(X[y]==X[x] && Y[y]<Y[x]) x=y;
	}
	double xx=0;
	while(1) {
		int ne=x;
		double mi=1e10;
		FOR(y,N) if(cr[x][y]>xx && cr[x][y]<mi) {
			ne=y;
			mi=cr[x][y];
		}
		if(mi>=1e10) break;
		S.insert(mi);
		xx=mi;
		x=ne;
	}
	
	x=0;
	FOR(y,N) {
		if(X[y]>X[x]) x=y;
		else if(X[y]>=X[x] && Y[y]>Y[x]) x=y;
	}
	
	xx=0;
	while(1) {
		int ne=x;
		double mi=1e10;
		FOR(y,N) if(cr[x][y]>xx && cr[x][y]<mi) {
			ne=y;
			mi=cr[x][y];
		}
		if(mi>=1e10) break;
		S.insert(mi);
		xx=mi;
		x=ne;
	}
	
	ITR(it,S) for(i=-2;i<=2;i++) val(*it+i);
	
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0