結果

問題 No.180 美しいWhitespace (2)
ユーザー ttkkggwwttkkggww
提出日時 2022-08-21 20:00:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,752 ms / 5,000 ms
コード長 909 bytes
コンパイル時間 4,489 ms
コンパイル使用メモリ 257,564 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 13:10:10
合計ジャッジ時間 24,970 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 13 ms
6,944 KB
testcase_06 AC 46 ms
6,940 KB
testcase_07 AC 102 ms
6,940 KB
testcase_08 AC 209 ms
6,940 KB
testcase_09 AC 666 ms
6,944 KB
testcase_10 AC 674 ms
6,944 KB
testcase_11 AC 1,419 ms
6,944 KB
testcase_12 AC 1,633 ms
6,944 KB
testcase_13 AC 1,390 ms
6,940 KB
testcase_14 AC 1,547 ms
6,940 KB
testcase_15 AC 1,588 ms
6,940 KB
testcase_16 AC 1,389 ms
6,940 KB
testcase_17 AC 1,423 ms
6,940 KB
testcase_18 AC 1,330 ms
6,940 KB
testcase_19 AC 808 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 1,752 ms
6,944 KB
testcase_31 AC 1,737 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 879 ms
6,944 KB
testcase_34 AC 871 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
using P = pair<ll,ll>;
vector<ll> a,b;
vector<P> ab;
ll n;

ll f(ll x){
	if(x<1)return 1e15;
	ll mx = a[0]+b[0]*x;;
	ll mn = a[0]+b[0]*x;;
	for(ll i = 0; i<n;i++){
		mx = max(mx,a[i]+b[i]*x);
		mn = min(mn,a[i]+b[i]*x);
	}
	return mx - mn;
}


void solve(){
	P ans(f(1),1);
	for(ll i = 0;i<n;i++){
		for(ll j = i+1;j<n;j++){
			//y = ai + bix
			//y = aj + bjx
			//0 = (ai-aj) + (bi-bj)x
			//x = (aj-ai)/(bi-bj)
			if(b[i]==b[j])continue;
			ll x = (a[j]-a[i])/(b[i]-b[j]);
			ans = min(ans,P(f(x),x));
			x++;
			ans = min(ans,P(f(x),x));
			x--;
			x--;
			ans = min(ans,P(f(x),x));
		}
	}
	cerr<<f(2)<<endl;
	cout<<ans.second<<endl;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n;
	a = b = vector<ll>(n);
	for(int i =0;i<n;i++)cin >> a[i] >> b[i];
	solve();
}
0