結果

問題 No.180 美しいWhitespace (2)
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-09-22 21:49:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,970 ms / 5,000 ms
コード長 1,926 bytes
コンパイル時間 1,462 ms
コンパイル使用メモリ 169,016 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-11 01:25:58
合計ジャッジ時間 34,183 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 21 ms
4,380 KB
testcase_06 AC 78 ms
4,380 KB
testcase_07 AC 172 ms
4,376 KB
testcase_08 AC 363 ms
4,376 KB
testcase_09 AC 609 ms
4,380 KB
testcase_10 AC 599 ms
4,376 KB
testcase_11 AC 2,422 ms
4,376 KB
testcase_12 AC 2,787 ms
4,380 KB
testcase_13 AC 2,356 ms
4,376 KB
testcase_14 AC 2,621 ms
4,376 KB
testcase_15 AC 2,699 ms
4,380 KB
testcase_16 AC 2,375 ms
4,380 KB
testcase_17 AC 2,433 ms
4,380 KB
testcase_18 AC 2,182 ms
4,376 KB
testcase_19 AC 805 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2,970 ms
4,380 KB
testcase_31 AC 2,970 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1,486 ms
4,376 KB
testcase_34 AC 1,484 ms
4,380 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++) {
                    if (y + dy <= 0) continue;
                    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