結果

問題 No.180 美しいWhitespace (2)
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-09-22 21:28:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,781 bytes
コンパイル時間 1,756 ms
コンパイル使用メモリ 170,496 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 18:30:18
合計ジャッジ時間 19,867 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 WA -
testcase_06 AC 35 ms
6,944 KB
testcase_07 AC 76 ms
6,940 KB
testcase_08 AC 153 ms
6,944 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1,185 ms
6,944 KB
testcase_13 AC 1,194 ms
6,944 KB
testcase_14 AC 1,197 ms
6,944 KB
testcase_15 AC 1,198 ms
6,940 KB
testcase_16 AC 1,191 ms
6,940 KB
testcase_17 AC 1,189 ms
6,940 KB
testcase_18 AC 1,187 ms
6,940 KB
testcase_19 AC 1,195 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
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
6,944 KB
testcase_30 AC 1,192 ms
6,944 KB
testcase_31 AC 1,190 ms
6,940 KB
testcase_32 AC 3 ms
6,944 KB
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        auto i = vs.begin();
        os << "[" << *i;
        for (++i; i != vs.end(); ++i) os << " " << *i;
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    const ll INF = 1LL<<56;

    int N;
    vector<int> A, B;
    void input() {
        cin >> N;
        A.resize(N);
        B.resize(N);
        for (int i = 0; i < N; i++) {
            cin >> A[i] >> B[i];
        }
    }

    ll C(ll x) {
        ll m = INF;
        ll M = 0; 
        for (int i = 0; i < N; i++) {
            m = min(m, A[i] + B[i] * x);
            M = max(M, A[i] + B[i] * x);
        }
        //cout << x << " -> " << M - m << endl;
        return M - m;
    }

    void solve() {
        if (N == 1) {
            cout << 0 << endl;
            return;
        }

        ll len = INF;
        int t = 1;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (B[i] == B[j]) continue;
                real x = - (A[i] - A[j]) / real(B[i] - B[j]);
                ll p = C(ll(floor(x)));
                if (len > p) {
                    len = p;
                    t = floor(x);
                }
                ll q = C(ll(ceil(x)));
                if (len > q) {
                    len = q;
                    t = ceil(x);
                }
            }
        }
        cout << t << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

0