結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 5 ms
6,944 KB
testcase_05 AC 22 ms
6,940 KB
testcase_06 AC 79 ms
6,944 KB
testcase_07 AC 175 ms
6,940 KB
testcase_08 AC 368 ms
6,940 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2,439 ms
6,940 KB
testcase_12 AC 2,811 ms
6,940 KB
testcase_13 AC 2,368 ms
6,940 KB
testcase_14 AC 2,637 ms
6,944 KB
testcase_15 AC 2,716 ms
6,940 KB
testcase_16 AC 2,389 ms
6,940 KB
testcase_17 AC 2,474 ms
6,940 KB
testcase_18 AC 2,256 ms
6,944 KB
testcase_19 AC 1,048 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2,984 ms
6,940 KB
testcase_31 AC 2,989 ms
6,944 KB
testcase_32 AC 4 ms
6,944 KB
testcase_33 AC 1,495 ms
6,940 KB
testcase_34 AC 1,496 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef long 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 = LLONG_MAX / 2LL;

    int N;
    vector<ll> 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 << 1 << endl;
            return;
        }

        ll len = C(1);
        ll t = 1;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (B[i] == B[j]) continue;
                ll x = - (A[i] - A[j]) / real(B[i] - B[j]);
                if (x <= 0) continue;
                ll y = floor(x);
                for (ll dy = -2; dy <= 2; dy++) {
                    ll p = C(y + dy);
                    if (len > p) {
                        len = p;
                        t = y + dy;
                    } else if (len == p) {
                        t = min(t, y + dy);
                    }
                }
            }
        }
        cout << t << endl;
    }
}

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

0