結果

問題 No.180 美しいWhitespace (2)
ユーザー 沙耶花
提出日時 2021-11-03 17:56:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 790 bytes
コンパイル時間 4,779 ms
コンパイル使用メモリ 251,968 KB
最終ジャッジ日時 2025-01-25 11:10:32
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /usr/include/c++/13/istream:41,
                 from /usr/include/c++/13/sstream:40,
                 from /usr/include/c++/13/complex:45,
                 from /usr/include/c++/13/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:127,
                 from main.cpp:2:
In member function ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]’,
    inlined from ‘int main()’ at main.cpp:43:8:
/usr/include/c++/13/ostream:204:25: warning: ‘x’ may be used uninitialized [-Wmaybe-uninitialized]
  204 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function ‘int main()’:
main.cpp:35:19: note: ‘x’ was declared here
   35 |         long long x;
      |                   ^

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 2000000000
int n;
vector<long long> a,b;

long long get(long long x){
	long long M = 0,m = 1000000000000000005;
	rep(i,n){
		M = max(M,a[i]+b[i]*x);
		m = min(m,a[i]+b[i]*x);
	}
	return M-m;
}

int main(){	
	
	cin>>n;
	a.resize(n),b.resize(n);
	rep(i,n)cin>>a[i]>>b[i];
	
	long long l = 1,r = 1000000005;
	while(r-l>3){
		long long m0 = l + (r-l)/3;
		long long m1 = m0 + (r-l)/3;
		if(get(m0)<=get(m1))r = m1;
		else l = m0;
	}
	long long ans = 100000000000000000;
	long long x;
	for(long long i=l;i<=r;i++){
		if(ans > get(i)){
			x =i;
			ans = get(i);
		}
	}
	
	cout<<x<<endl;
	
	return 0;
	
}
0