結果

問題 No.180 美しいWhitespace (2)
ユーザー yumakmcyumakmc
提出日時 2016-02-18 04:45:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,451 bytes
コンパイル時間 1,298 ms
コンパイル使用メモリ 163,136 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 06:32:26
合計ジャッジ時間 2,690 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;


vector<long long >as,bs;
long long check(const long long  tab){
	long long amin = as[0] + bs[0] * tab;
	long long amax = as[0] + bs[0] * tab;

	for (int i = 1; i < as.size(); ++i){
		long long len = as[i] + bs[i] * tab;
		amin = min(amin, len);
		amax = max(amax, len);
	}
	return amax-amin;
}
int main() {
	int N; cin >> N;
	as.resize(N);
	bs.resize(N);
	for (int i = 0; i < N; ++i){
		cin >> as[i] >> bs[i];
	}
	long long  amin = 0;
	long long amax = 5e9;
	{
		int num = 1000;
		while (num--, num){
			long long amid0 = (amin * 2 + amax) / 3;
			long long amid1 = (amin + amax * 2) / 3;
			if (check(amid0) < check(amid1)){
				amax = amid1;
			}
			else{
				amin = amid0;
			}
		}
	}
	long long anslen = check(amin);
	for (long long  i = amin; i < amax; ++i){
		anslen = min(check(i), anslen);
	}
	long long from;
	for (long long i = amin; i < amax; ++i){
		if (anslen == check(i)){
			from = i;
			break;
		}
	}
	if (from != amin){
		cout << from << endl;
		return 0;
	}else
	{
		long long  amin = 0;
		long long amax = from;
		if (!from){
			cout << 1 << endl;
			return 0;
		}
		while (amin+1!=amax){
			long long amid = (amin + amax) / 2;
			if (check(amid) == anslen){
				amax = amid;
			}
			else{
				amin = amid;
			}
		}
		cout << amax << endl;
	}
	return 0;
}
0