結果

問題 No.180 美しいWhitespace (2)
ユーザー omuomu
提出日時 2015-04-07 07:34:43
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,122 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 7,684 KB
最終ジャッジ日時 2023-09-17 06:26:58
合計ジャッジ時間 7,093 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:111:10: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  cout << ans << endl;
          ^~~

ソースコード

diff #

#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];

double solve(double x){
	double Max = 0,Min = INF;
	rep(i, n){
		double 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;
	}
	rep(i, n - 1){
		if (b[i] == b[i + 1]){
			if (i == n - 2){
				cout << 0 << endl;return 0;
			}
		}
		else break;
	}

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

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

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

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

		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