結果

問題 No.2594 Mix shake!!
ユーザー 👑 hitonanodehitonanode
提出日時 2023-11-29 01:14:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 2,370 bytes
コンパイル時間 6,794 ms
コンパイル使用メモリ 413,712 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-20 12:16:04
合計ジャッジ時間 11,151 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 5 ms
6,676 KB
testcase_19 AC 6 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 6 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 3 ms
6,676 KB
testcase_30 AC 3 ms
6,676 KB
testcase_31 AC 3 ms
6,676 KB
testcase_32 AC 5 ms
6,676 KB
testcase_33 AC 6 ms
6,676 KB
testcase_34 AC 35 ms
6,676 KB
testcase_35 AC 36 ms
6,676 KB
testcase_36 AC 36 ms
6,676 KB
testcase_37 AC 36 ms
6,676 KB
testcase_38 AC 36 ms
6,676 KB
testcase_39 AC 34 ms
6,676 KB
testcase_40 AC 35 ms
6,676 KB
testcase_41 AC 36 ms
6,676 KB
testcase_42 AC 36 ms
6,676 KB
testcase_43 AC 36 ms
6,676 KB
testcase_44 AC 36 ms
6,676 KB
testcase_45 AC 30 ms
6,676 KB
testcase_46 AC 36 ms
6,676 KB
testcase_47 AC 36 ms
6,676 KB
testcase_48 AC 37 ms
6,676 KB
testcase_49 AC 36 ms
6,676 KB
testcase_50 AC 36 ms
6,676 KB
testcase_51 AC 30 ms
6,676 KB
testcase_52 AC 36 ms
6,676 KB
testcase_53 AC 36 ms
6,676 KB
testcase_54 AC 5 ms
6,676 KB
testcase_55 AC 5 ms
6,676 KB
testcase_56 AC 1 ms
6,676 KB
testcase_57 AC 2 ms
6,676 KB
testcase_58 AC 4 ms
6,676 KB
testcase_59 AC 3 ms
6,676 KB
testcase_60 AC 2 ms
6,676 KB
testcase_61 AC 2 ms
6,676 KB
testcase_62 AC 2 ms
6,676 KB
testcase_63 AC 2 ms
6,676 KB
testcase_64 AC 3 ms
6,676 KB
testcase_65 AC 2 ms
6,676 KB
testcase_66 AC 5 ms
6,676 KB
testcase_67 AC 3 ms
6,676 KB
testcase_68 AC 6 ms
6,676 KB
testcase_69 AC 3 ms
6,676 KB
testcase_70 AC 6 ms
6,676 KB
testcase_71 AC 3 ms
6,676 KB
testcase_72 AC 2 ms
6,676 KB
testcase_73 AC 2 ms
6,676 KB
testcase_74 AC 2 ms
6,676 KB
testcase_75 AC 1 ms
6,676 KB
testcase_76 AC 2 ms
6,676 KB
testcase_77 AC 1 ms
6,676 KB
testcase_78 AC 2 ms
6,676 KB
testcase_79 AC 2 ms
6,676 KB
testcase_80 AC 5 ms
6,676 KB
testcase_81 AC 2 ms
6,676 KB
testcase_82 AC 4 ms
6,676 KB
testcase_83 AC 2 ms
6,676 KB
testcase_84 AC 4 ms
6,676 KB
testcase_85 AC 2 ms
6,676 KB
testcase_86 AC 2 ms
6,676 KB
testcase_87 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;

#include <boost/multiprecision/cpp_int.hpp>
using Rational = boost::multiprecision::cpp_rational;

vector<pair<Rational, Rational>> to_slope(const vector<tuple<Rational, Rational, Rational, int>> &AB) {
    Rational x(0), y(0);
    vector<pair<Rational, Rational>> ret;
    for (auto [_, a, b, i] : AB) {
        x += a;
        y += b;
        ret.emplace_back(x, y);
    }
    return ret;
}

bool solve() {
    int N;
    cin >> N;

    vector<Rational> A(N), B(N), C(N), D(N);
    for (auto &x : A) cin >> x;
    for (auto &x : B) cin >> x;
    for (auto &x : C) cin >> x;
    for (auto &x : D) cin >> x;

    vector<tuple<Rational, Rational, Rational, int>> AB, CD;
    for (int i = 0; i < N; ++i) {
        AB.emplace_back(B.at(i) / A.at(i), A.at(i), B.at(i), i);
        CD.emplace_back(D.at(i) / C.at(i), C.at(i), D.at(i), i);
    }

    sort(AB.begin(), AB.end());
    sort(CD.begin(), CD.end());

    const auto lb_xys = to_slope(AB);
    const auto ub_xys = to_slope(CD);

    {
        Rational x0(0), y0(0);
        for (int i = 0; i < (int)lb_xys.size(); ++i) {
            auto [x1, y1] = lb_xys.at(i);

            for (auto [x, y] : ub_xys) {
                if ((x1 - x0) * (y - y0) - (y1 - y0) * (x - x0) < 0) return false;
            }

            x0 = x1, y0 = y1;
        }
    }

    {
        bool same = true;
        for (int i = 0; i < N; ++i) same &= get<3>(AB.at(i)) == get<3>(CD.at(i));
        if (same) return true;
    }

    Rational vx(0), vy(0);

    for (int i = 0; i + 1 < N; ++i) {
        // cerr << i << " " << vx << " " << vy << endl;
        const auto &[px, py] = ub_xys.at(i);

        if (px <= vx) return true;

        // y = a1 x + b1
        const Rational a1 = (py - vy) / (px - vx);
        const Rational b1 = vy - a1 * vx;

        // y = a2 x + b2
        const auto &[ax, ay] = lb_xys.at(i);
        const auto &[bx, by] = lb_xys.at(i + 1);

        const Rational a2 = (by - ay) / (bx - ax);
        const Rational b2 = ay - a2 * ax;

        if (a1 >= a2) return true;

        vx = (b2 - b1) / (a1 - a2);
        vy = a1 * vx + b1;

        if (vx >= bx) return true;
    }

    return false;
}

int main() {
    cin.tie(nullptr);
    cin.sync_with_stdio(false);

    cout << (solve() ? "Yes" : "No") << '\n';
}
0