結果
問題 |
No.180 美しいWhitespace (2)
|
ユーザー |
![]() |
提出日時 | 2015-04-06 00:39:51 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,614 bytes |
コンパイル時間 | 765 ms |
コンパイル使用メモリ | 93,988 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-04 02:48:58 |
合計ジャッジ時間 | 2,134 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 4 WA * 27 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <cmath> #include <algorithm> #include <cstdlib> #include <ctime> #include <cstdio> #include <functional> #include <set> #include <sstream> #include <map> #include <queue> #include <stack> using namespace std; int n; unsigned long long a[1001],b[1001]; unsigned long long f(unsigned long long x) { unsigned long long _max=a[0]+b[0]*x,_min=a[0]+b[0]*x; for(int i=1;i<n;i++){ _max=max(_max,a[i]+b[i]*x); _min=min(_min,a[i]+b[i]*x); } return _max-_min; } //下に凸 unsigned long long f2(unsigned long long x) { return f(x)*f(x); } // left-ml-mr-right unsigned long long search(unsigned long long left, unsigned long long right) { for (long long i = 0; i < 10000; i++){ unsigned long long ml=(right-left)/3,mr=2*(right-left)/3; unsigned long long fl=f2(ml),fr=f2(mr); if(fl>fr) left=ml; else right=mr; } return (right + left)/2; } int main() { cin>>n; set<pair<unsigned long long,unsigned long long> > s; for(int i=0;i<n;i++){ cin>>a[i]>>b[i]; s.insert(make_pair(a[i],b[i])); } if(s.size()==1){cout<<1<<endl; return 0;} unsigned long long left=1,right=1e6; unsigned long long mid=search(left,right); // cout<<mid<<endl; vector<pair<unsigned long long,unsigned long long> > vp; vp.push_back(make_pair(f(mid-2),mid-2)); vp.push_back(make_pair(f(mid-1),mid-1)); vp.push_back(make_pair(f(mid),mid)); vp.push_back(make_pair(f(mid+1),mid+1)); vp.push_back(make_pair(f(mid+2),mid+2)); sort(vp.begin(),vp.end()); for(int i=0;i<5;i++){ if(vp[i].second>0){ cout<<vp[i].second<<endl; break;} } return 0; }