結果

問題 No.180 美しいWhitespace (2)
コンテスト
ユーザー omu
提出日時 2015-04-07 06:56:39
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,069 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 601 ms
コンパイル使用メモリ 107,084 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-25 12:06:51
合計ジャッジ時間 13,496 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7 WA * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/string:53,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/locale_classes.h:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ios_base.h:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ios:46,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
                 from main.cpp:3:
In function 'const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = int]',
    inlined from 'int main()' at main.cpp:108:13:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:239:7: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
  239 |       if (__b < __a)
      |       ^~
main.cpp: In function 'int main()':
main.cpp:100:13: note: 'ans' was declared here
  100 |         int ans;int Min = INF;
      |             ^~~

ソースコード

diff #
raw source code

#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <list>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

#define rep(i,n)  for(int (i) = 0;(i) < (n);(i)++)
#define clr(a) memset((a), 0 ,sizeof(a))
#define mclr(a) memset((a), -1 ,sizeof(a))
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) (sizeof(a))
#define Fill(a,v) fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)
bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 2147483647;

int n;
int a[1010], b[1010];

int solve(int x){
	int Max = 0,Min = INF;
	rep(i, n){
		int v = a[i] + b[i]*x;
		Max = max(v,Max);
		Min = min(v,Min);
	}
	return Max - Min;
}

int main()
{
	cin >> n;
	rep(i, n){
		cin >> a[i] >> b[i];
	}

	rep(i, n - 1){
		if (a[i] == a[i + 1] && b[i] == b[i + 1]){
			if (i == n - 2){
				cout << 1 << endl;return 0;
			}
		}
		else{
			break;
		}
	}

	int l=0,r=INF/1000;
	int m1,m2;


	int olr = r,oll = l;
	while (1){
		m1 = (l+r)/3*1;
		m2 = (l+r)/3*2;

		int m1v = solve(m1);
		int m2v = solve(m2);

		if (m1v > m2v){
			l = m1;
		}
		if (m1v < m2v){
			r = m2;
		}
		if (m1v == m2v){
			l = m1;
			r = m2;
		}

		if (olr == r && oll == l)
			break;

		olr = r;oll = l;

		if (abs(l-r) < 100000)
			break;
	}

	int ans;int Min = INF;
	for (int i = l; i <= r; i++){
		int t = solve(i);
		if (t < Min){
			Min = t;
			ans = i;
		}
		if (t == Min){
			ans = min(i,ans);
		}
	}

	cout << ans << endl;
	return 0;
}
0