結果
| 問題 | 
                            No.180 美しいWhitespace (2)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             codershifth
                         | 
                    
| 提出日時 | 2016-01-27 00:05:00 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2,552 ms / 5,000 ms | 
| コード長 | 1,722 bytes | 
| コンパイル時間 | 1,444 ms | 
| コンパイル使用メモリ | 168,068 KB | 
| 実行使用メモリ | 68,480 KB | 
| 最終ジャッジ日時 | 2024-09-21 17:39:00 | 
| 合計ジャッジ時間 | 11,504 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 31 | 
ソースコード
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()
using namespace std;
class BeautifulWhitespace2 {
public:
    void solve_TLE(void) {
        int N;
        cin>>N;
        vector<ll> a(N);
        vector<ll> b(N);
        REP(i,N) cin>>a[i]>>b[i];
        auto solve = [=](int i, int j)->ll {
            if ( i == j || b[i] == b[j] )
                return -1;
            // a[i]+b[i]*x = a[j]+b[j]*x
            // x*(b[i]-b[j]) = a[j]-a[i]
            return (a[j]-a[i])/(b[i]-b[j]);
        };
        // O(N^2)
        set<int> xs;
        REP(i,N)
        FOR(j,i+1,N)
        {
            ll x = solve(i,j);
            xs.insert(x-1);
            xs.insert(x);
            xs.insert(x+1);
        }
        // O(N)
        auto f = [=](ll x) {
            ll maxF = a[0]+b[0]*x;
            ll minF = a[0]+b[0]*x;
            FOR(i,1,N)
            {
                minF = min(minF, a[i]+b[i]*x);
                maxF = max(maxF, a[i]+b[i]*x);
            }
            return maxF - minF;
        };
        ll minX = 1;
        ll minY = 1<<30;
        for (auto x : xs)
        {
            if (x <= 0)
                continue;
            ll y = f(x);
            if (y >= minY)
                continue;
            minY = y;
            minX = x;
        }
        cout<<minX<<endl;
    }
    void solve(void)
    {
        solve_TLE();
    }
};
#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new BeautifulWhitespace2();
        obj->solve();
        delete obj;
        return 0;
}
#endif
            
            
            
        
            
codershifth