結果
| 問題 | No.180 美しいWhitespace (2) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-04-06 23:59:48 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,528 bytes |
| 記録 | |
| コンパイル時間 | 715 ms |
| コンパイル使用メモリ | 112,172 KB |
| 実行使用メモリ | 6,144 KB |
| 最終ジャッジ日時 | 2026-03-25 12:01:20 |
| 合計ジャッジ時間 | 1,791 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 31 |
コンパイルメッセージ
In file included 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: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:68:13:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:212:25: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
212 | { return _M_insert(__n); }
| ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:60:15: note: 'ans' was declared here
60 | long long ans;
| ^~~
ソースコード
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;
long long getUgliness(const vector<int>& a, const vector<int>& b, long long x)
{
int n = a.size();
long long minLen = LLONG_MAX;
long long maxLen = LLONG_MIN;
for(int i=0; i<n; ++i){
long long len = a[i] + b[i] * x;
minLen = min(minLen, len);
maxLen = max(maxLen, len);
}
return maxLen - minLen;
}
int main()
{
int n;
cin >> n;
vector<int> a(n), b(n);
for(int i=0; i<n; ++i)
cin >> a[i] >> b[i];
long long left = 1;
long long right = 1000000000;
while(right - left >= 3){
long long mid1 = (left * 2 + right) / 3;
long long mid2 = (left + right * 2) / 3;
long long x = getUgliness(a, b, mid1);
long long y = getUgliness(a, b, mid2);
if(x <= y)
right = mid2;
else
left = mid1;
}
long long minUgliness = LLONG_MAX;
long long ans;
for(long long i=left; i<=right; ++i){
long long ugliness = getUgliness(a, b, i);
if(ugliness < minUgliness){
ans = i;
minUgliness = ugliness;
}
}
cout << ans << endl;
return 0;
}