結果

問題 No.2628 Shrinkage
ユーザー SnowBeenDidingSnowBeenDiding
提出日時 2024-02-16 21:36:55
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 16,217 bytes
コンパイル時間 5,361 ms
コンパイル使用メモリ 331,544 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-09-28 19:51:10
合計ジャッジ時間 6,105 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
const long long MOD = 998244353;
// using mint = modint1000000007;
// const long long MOD = 1000000007;
// using mint = modint;//mint::set_mod(MOD);

#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repeq(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); i++)
#define repreq(i, a, b) for (ll i = (ll)(a); i >= (ll)(b); i--)
#define endl '\n'  // fflush(stdout);
#define cYes cout << "Yes" << endl
#define cNo cout << "No" << endl
#define sortr(v) sort(v, greater<>())
#define pb push_back
#define pob pop_back
#define mp make_pair
#define mt make_tuple
#define FI first
#define SE second
#define ALL(v) (v).begin(), (v).end()
#define INFLL 3000000000000000100LL
#define INF 1000000100
#define PI acos(-1.0L)
#define TAU (PI * 2.0L)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef tuple<ll, ll, ll> Tlll;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<ll> Vl;
typedef vector<Vl> VVl;
typedef vector<VVl> VVVl;
typedef vector<Tlll> VTlll;
typedef vector<mint> Vm;
typedef vector<Vm> VVm;
typedef vector<string> Vs;
typedef vector<double> Vd;
typedef vector<char> Vc;
typedef vector<bool> Vb;
typedef vector<Pll> VPll;
typedef priority_queue<ll> PQl;
typedef priority_queue<ll, vector<ll>, greater<ll>> PQlr;

/* inout */
ostream &operator<<(ostream &os, mint const &m) {
    os << m.val();
    return os;
}
istream &operator>>(istream &is, mint &m) {
    long long n;
    is >> n, m = n;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    int n = v.size();
    rep(i, 0, n) { os << v[i] << " \n"[i == n - 1]; }
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
    int n = v.size();
    rep(i, 0, n) os << v[i];
    return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> const &p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const map<T, S> &ma) {
    for (auto &[key, val] : ma) {
        os << key << ':' << val << '\n';
    }
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &st) {
    auto itr = st.begin();
    for (int i = 0; i < (int)st.size(); i++) {
        os << *itr << (i + 1 != (int)st.size() ? ' ' : '\n');
        itr++;
    }
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, multiset<T> &st) {
    auto itr = st.begin();
    for (int i = 0; i < (int)st.size(); i++) {
        os << *itr << (i + 1 != (int)st.size() ? ' ' : '\n');
        itr++;
    }
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, queue<T> q) {
    while (q.size()) {
        os << q.front();
        q.pop();
        os << " \n"[q.empty()];
    }
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, stack<T> st) {
    vector<T> v;
    while (st.size()) {
        v.push_back(st.top());
        st.pop();
    }
    reverse(ALL(v));
    os << v;
    return os;
}
template <class T, class Container, class Compare>
ostream &operator<<(ostream &os, priority_queue<T, Container, Compare> pq) {
    vector<T> v;
    while (pq.size()) {
        v.push_back(pq.top());
        pq.pop();
    }
    os << v;
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &in : v) is >> in;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
    is >> p.first >> p.second;
    return is;
}

/* useful */
template <typename T>
int SMALLER(vector<T> &a, T x) {
    return lower_bound(a.begin(), a.end(), x) - a.begin();
}
template <typename T>
int orSMALLER(vector<T> &a, T x) {
    return upper_bound(a.begin(), a.end(), x) - a.begin();
}
template <typename T>
int BIGGER(vector<T> &a, T x) {
    return a.size() - orSMALLER(a, x);
}
template <typename T>
int orBIGGER(vector<T> &a, T x) {
    return a.size() - SMALLER(a, x);
}
template <typename T>
int COUNT(vector<T> &a, T x) {
    return upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
}
template <typename T, typename S>
bool chmax(T &a, S b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename S>
bool chmin(T &a, S b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void press(T &v) {
    v.erase(unique(ALL(v)), v.end());
}
template <typename T>
vector<int> zip(vector<T> a) {
    int n = a.size();
    pair<T, int> p[n];
    vector<int> v(n);
    for (int i = 0; i < n; i++) p[i] = make_pair(a[i], i);
    sort(p, p + n);
    int w = 0;
    for (int i = 0; i < n; i++) {
        if (i && p[i].first != p[i - 1].first) w++;
        v[p[i].second] = w;
    }
    return v;
}
template <typename T>
vector<T> vis(vector<T> &v) {
    vector<T> S(v.size() + 1);
    rep(i, 1, S.size()) S[i] += v[i - 1] + S[i - 1];
    return S;
}
template <typename T>
T ceil_div(T a, T b) {
    if (b < 0) a = -a, b = -b;
    return (a >= 0 ? (a + b - 1) / b : a / b);
}
template <typename T>
T floor_div(T a, T b) {
    if (b < 0) a = -a, b = -b;
    return (a >= 0 ? a / b : (a - b + 1) / b);
}
ll dtoll(double d, int g) { return round(d * pow(10, g)); }

const double EPS = 1e-10;

void init() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    cout.precision(12);
    cout << fixed;
}

// do {} while (next_permutation(ALL(vec)));

/********************************** START **********************************/

void sol();

int main() {
    init();
    int q = 1;
    cin >> q;
    while (q--) sol();
    return 0;
}

/********************************** SOLVE **********************************/

// #define EPS (1e-10)
// #define PI (acos(-1))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;

// point
using P = complex<ld>;

// two points: line
using L = array<P, 2>;

// circle
struct C {
    P c;
    ld r;
    C() : c({0, 0}), r(0) {}
    C(const P &c_, ld r_) : c(c_), r(r_) {}
    C(ld x_, ld y_, ld r_) : c({x_, y_}), r(r_) {}
};

using VP = vector<P>;
using VC = vector<C>;

void Pin(P &a, ld b, ld c) {
    a.real(b);
    a.imag(c);
}

void Lin(L &a, P b, P c) {
    a[0] = b;
    a[1] = c;
}

ostream &operator<<(ostream &os, P const &A) {
    os << A.real() << ' ' << A.imag();
    return os;
}

namespace std {
bool operator<(const P &a, const P &b) { return arg(a) < arg(b); }
}  // namespace std

ld cross(const P &a, const P &b) { return imag(conj(a) * b); }

ld dot(const P &a, const P &b) { return real(conj(a) * b); }

// 線分ABをs:tに内分する点
P bun(P A, P B, double s, double t) {
    complex<ld> S(t / (s + t)), T(s / (s + t));
    return A * S + B * T;
}

// a->b->cの進行方向
int ccw(P a, P b, P c) {
    b -= a;
    c -= a;
    if (cross(b, c) > 0) return 1;     // counterclockwise a--b//c
    if (cross(b, c) < 0) return -1;    // clockwise        a--b\\c
    if (dot(b, c) < 0) return 2;       // c--a--b on line
    if (norm(b) < norm(c)) return -2;  // a--b--c on line
    return 0;                          // a--c--b on line
}

// 直線-直線交差判定
bool intersectLL(const L &l, const L &m) {
    return abs(cross(l[1] - l[0], m[1] - m[0])) > EPS      // non-parallel
           || abs(cross(l[1] - l[0], m[1] - l[0])) < EPS;  // same line
}

// 直線-線分交差判定
bool intersectLS(const L &l, const L &s) {
    return cross(l[1] - l[0], s[0] - l[0]) *  // s[0] is left of l
               cross(l[1] - l[0], s[1] - l[0]) <
           EPS;  // s[1] is right of l
}

// 線分-線分交差判定
bool intersectSS(const L &s, const L &t) {
    return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
           ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}

// 点∈直線の判定
bool intersectLP(const L &l, const P &p) {
    return abs(cross(l[1] - p, l[0] - p)) < EPS;
}

// 点∈線分の判定
bool intersectSP(const L &s, const P &p) {
    // triangle inequality
    return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < EPS;
}

// 点の直線への射影
P projection(const L &l, const P &p) {
    ld t = dot(p - l[0], l[1] - l[0]) / norm(l[1] - l[0]);
    return l[0] + t * (l[1] - l[0]);
}

// 点の直線に対する鏡映
P reflection(const L &l, const P &p) {
    return p + (projection(l, p) - p) * 2.L;
}

// 点-直線の距離
ld distanceLP(const L &l, const P &p) { return abs(p - projection(l, p)); }

// 直線-直線の距離 非平行か同一なら0
ld distanceLL(const L &l, const L &m) {
    return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}

// 直線-線分の距離
ld distanceLS(const L &l, const L &s) {
    return intersectLS(l, s) ? 0
                             : min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}

// 点-線分の距離
ld distanceSP(const L &s, const P &p) {
    const P r = projection(s, p);
    if (intersectSP(s, r)) return abs(r - p);
    return min(abs(s[0] - p), abs(s[1] - p));
}

// 線分-線分の距離
ld distanceSS(const L &s, const L &t) {
    if (intersectSS(s, t)) return 0;
    return min({distanceSP(s, t[0]), distanceSP(s, t[1]), distanceSP(t, s[0]),
                distanceSP(t, s[1])});
}

// 2直線の交点 平行な場合は例外
P crosspoint(const L &l, const L &m) {
    ld A = cross(l[1] - l[0], m[1] - m[0]);
    ld B = cross(l[1] - l[0], l[1] - m[0]);
    return m[0] + B / A * (m[1] - m[0]);
}

// 2円の交点 一致する場合は例外
VP crosspoint(C a, C b) {
    ld dist = abs(a.c - b.c);
    ld rdist = abs(a.r - b.r);
    assert(dist >= EPS || rdist >= EPS);
    // 外接する
    if (abs(dist - (a.r + b.r)) < EPS) {
        return {(b.r * a.c + a.r * b.c) / (a.r + b.r)};
    }
    // 内接する
    if (abs(dist - rdist) < EPS) {
        return {(-b.r * a.c + a.r * b.c) / (a.r - b.r)};
    }
    // 離れている、内包する
    if (dist > a.r + b.r || dist < rdist) {
        return {};
    }
    // 交わる 中心を0と1に規格化
    // 最後に足す
    P movp = a.c;
    a.c = {0.L, 0.L};
    b.c -= movp;
    // 最後に掛ける
    P movm = b.c;
    b.c = {1.L, 0.L};
    a.r /= abs(movm);
    b.r /= abs(movm);
    ld x = (a.r * a.r - b.r * b.r + 1) / 2;
    ld y = sqrt(a.r * a.r - x * x);
    P cr1 = {x, y};
    P cr2 = {x, -y};
    cr1 = cr1 * movm + movp;
    cr2 = cr2 * movm + movp;
    // 元に戻す
    return {cr1, cr2};
}

// 円盤の最大の重なりの個数 O(n^3)
ll maxOverlap(const VC &vc) {
    ll n = vc.size();
    if (!n) return 0;
    ll ret = 1;
    VP pts;
    for (auto &&e : vc) {
        pts.emplace_back(e.c);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            VP cp = crosspoint(vc[i], vc[j]);
            pts.insert(pts.end(), cp.begin(), cp.end());
        }
    }
    for (auto &&e : pts) {
        ll tmp = 0;
        for (auto &&ee : vc) {
            tmp += (abs(e - ee.c) < ee.r + EPS);
        }
        if (ret < tmp) ret = tmp;
    }
    return ret;
}

// 多角形の面積
ld Area(const VP &p) {
    ll ret = 0;
    for (int i = 1; i + 1 < (int)p.size(); i++) {
        ret += round(cross(p[i] - p[0], p[i + 1] - p[0]));
    }
    return (ld)abs(ret) / 2;
}

// 凸性判定 点列は時計/反時計
bool isConvex(const VP &p) {
    int n = p.size();
    assert(n >= 3);
    int cnt[5] = {};
    for (int i = 0; i < n; i++) {
        cnt[ccw(p[i], p[(i + 1) % n], p[(i + 2) % n]) + 2]++;
    }
    return cnt[1] == 0 || cnt[3] == 0;
}

// 凸包 時計回り
VP ConvexHull(VP p) {
    sort(p.begin(), p.end(), [](const auto &l, const auto &r) {
        return real(l) != real(r) ? real(l) < real(r) : imag(l) < imag(r);
    });
    int n = p.size();
    if (n < 3) return p;
    VP upper, lower;
    upper.reserve(n);
    lower.reserve(n);
    int sz = 0;
    for (int i = 0; i < n; i++) {
        upper.emplace_back(p[i]);
        sz++;
        while (sz >= 3 &&
               ccw(upper[sz - 3], upper[sz - 2], upper[sz - 1]) == 1) {
            upper.erase(upper.end() - 2);
            sz--;
        }
    }
    sz = 0;
    for (int i = n - 1; i >= 0; i--) {
        lower.emplace_back(p[i]);
        sz++;
        while (sz >= 3 &&
               ccw(lower[sz - 3], lower[sz - 2], lower[sz - 1]) == 1) {
            lower.erase(lower.end() - 2);
            sz--;
        }
    }
    upper.pop_back();
    lower.pop_back();
    copy(lower.begin(), lower.end(), back_inserter(upper));
    return upper;
}

// 多角形が点pを含むか 点列は時計/反時計 内2, 辺上1, 外0 O(V)
int PointInPolygon(const VP &g, const P &p) {
    int n = g.size();
    ld r = 0;
    assert(n >= 2);
    for (int i = 0; i < n; i++) {
        if (ccw(g[i], g[(i + 1) % n], p) == 0) return 1;
        r += arg((g[(i + 1) % n] - p) / (g[i] - p));
    }
    return abs(r) > PI ? 2 : 0;
}

// キャリパー法(Rotating Calipers法)
// 凸多角形を回転しながら走査し、最遠点対を求める
ld Diameter(const VP &p) {
    auto qs = ConvexHull(p);
    reverse(qs.begin(), qs.end());
    int n = qs.size();
    if (n == 2) return abs(qs[0] - qs[1]);
    int i = 0, j = 0;
    auto cmp = [](const P &a, const P &b) {
        return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag();
    };
    for (int k = 0; k < n; k++) {
        if (cmp(qs[k], qs[i])) i = k;
        if (cmp(qs[j], qs[k])) j = k;
    }
    ld ret = 0;
    int si = i, sj = j;
    while (i != sj || j != si) {
        ret = max(ret, abs(qs[i] - qs[j]));
        if (cross(qs[(i + 1) % n] - qs[i], qs[(j + 1) % n] - qs[j]) < 0) {
            i = (i + 1) % n;
        } else {
            j = (j + 1) % n;
        }
    }
    return ret;
}

// 凸多角形の切断
// 凸多角形pを直線lで切断したときの面積(切断の向きの左側)
// https://onlinejudge.u-aizu.ac.jp/services/room.html#GEOMETRY_20231005/problems/M
ld ConvexCut(const VP &p, const L &l) {
    int n = p.size();
    VP q;
    for (int i = 0; i < n; i++) {
        P a = p[i], b = p[(i + 1) % n];
        if (ccw(l[0], l[1], a) != -1) q.emplace_back(a);
        if (ccw(l[0], l[1], a) * ccw(l[0], l[1], b) < 0) {
            if (abs(cross(l[1] - l[0], b - a)) < EPS) {
                q.emplace_back(a);
            } else {
                q.emplace_back(crosspoint(L{a, b}, l));
            }
        }
    }
    ld ret = 0;
    for (int i = 0; i < (int)q.size(); i++) {
        ret += cross(q[i], q[(i + 1) % q.size()]);
    }
    return abs(ret) / 2;
}

// 2円の共通接線の本数(0, 1, 2, 3, 4)
// https://onlinejudge.u-aizu.ac.jp/services/room.html#GEOMETRY_20231005/problems/N
ll tangentlines(C a, C b) {
    ld dist = abs(a.c - b.c);
    ld rdist = abs(a.r - b.r);
    if (dist < rdist) return 0;
    if (abs(dist - rdist) < EPS) return 1;
    if (dist < a.r + b.r) return 2;
    if (abs(dist - a.r - b.r) < EPS) return 3;
    return 4;
}

// 三角形の内接円
C InCircle(P a, P b, P c) {
    ld a1 = abs(b - c);
    ld a2 = abs(c - a);
    ld a3 = abs(a - b);
    ld s = (a1 + a2 + a3) / 2;
    ld r = sqrtl(s * (s - a1) * (s - a2) * (s - a3)) / s;
    P p = (a1 * a + a2 * b + a3 * c) / (a1 + a2 + a3);
    return C(p, r);
}

void sol() {
    P p0, p1, q0, q1;
    rep(i, 0, 4) {
        ld x, y;
        cin >> x >> y;
        if (i == 0) Pin(p0, x, y);
        if (i == 1) Pin(p1, x, y);
        if (i == 2) Pin(q0, x, y);
        if (i == 3) Pin(q1, x, y);
    }
    L l0 = {p0, q0}, l1 = {p1, q1};
    if (!intersectLL(l0, l1)) {
        cout << "No" << endl;
        return;
    }
    P c = crosspoint(l0, l1);
    double d0 = abs(c - q0) / abs(c - p0);
    double d1 = abs(c - q1) / abs(c - p1);
    if (d0 >= 1 || d1 >= 1) {
        cout << "No" << endl;
        return;
    }
    if (abs(d0 - d1) < EPS) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
0