結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 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,504 KB
testcase_06 AC 3 ms
7,084 KB
testcase_07 AC 3 ms
7,348 KB
testcase_08 AC 4 ms
7,680 KB
testcase_09 AC 7 ms
11,244 KB
testcase_10 AC 6 ms
11,344 KB
testcase_11 AC 7 ms
11,484 KB
testcase_12 AC 7 ms
11,292 KB
testcase_13 AC 7 ms
11,332 KB
testcase_14 AC 7 ms
11,344 KB
testcase_15 AC 7 ms
11,268 KB
testcase_16 AC 6 ms
11,244 KB
testcase_17 AC 6 ms
11,292 KB
testcase_18 AC 7 ms
11,340 KB
testcase_19 AC 7 ms
11,272 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 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 7 ms
11,344 KB
testcase_31 AC 7 ms
11,276 KB
testcase_32 AC 6 ms
11,292 KB
testcase_33 AC 6 ms
11,344 KB
testcase_34 AC 7 ms
11,396 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;
ll m=1LL<<60;
double cr[1010][1010];

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


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) cr[x][y] = (Y[x]==Y[y]) ? -1 : (X[y]-X[x])*1.0/(Y[x]-Y[y]);
	
	set<double> S;
	S.insert(1);
	
	FOR(i,2) {
		x=0;
		FOR(y,N) {
			if(i==0 && ((X[y]<X[x]) || (X[y]==X[x] && Y[y]<Y[x]))) x=y;
			if(i==1 && ((X[y]>X[x]) || (X[y]==X[x] && Y[y]>Y[x]))) x=y;
		}
		for(double xx=0;;) {
			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