結果

問題 No.180 美しいWhitespace (2)
ユーザー omuomu
提出日時 2015-04-07 06:56:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,069 bytes
コンパイル時間 651 ms
コンパイル使用メモリ 86,092 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 06:25:52
合計ジャッジ時間 16,595 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 135 ms
4,376 KB
testcase_05 AC 216 ms
4,376 KB
testcase_06 AC 372 ms
4,380 KB
testcase_07 AC 493 ms
4,376 KB
testcase_08 AC 403 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
4,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 2 ms
4,376 KB
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:112: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];

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