結果

問題 No.2602 Real Collider
ユーザー dyktr_06dyktr_06
提出日時 2024-01-13 01:14:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 18,731 bytes
コンパイル時間 3,311 ms
コンパイル使用メモリ 246,540 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-28 00:58:14
合計ジャッジ時間 37,056 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1,225 ms
5,376 KB
testcase_11 AC 425 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 293 ms
5,376 KB
testcase_16 AC 466 ms
5,376 KB
testcase_17 AC 535 ms
5,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 632 ms
5,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 289 ms
5,376 KB
testcase_27 WA -
testcase_28 AC 513 ms
5,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 465 ms
5,376 KB
testcase_32 AC 400 ms
5,376 KB
testcase_33 AC 497 ms
5,376 KB
testcase_34 AC 500 ms
5,376 KB
testcase_35 AC 283 ms
5,376 KB
testcase_36 AC 281 ms
5,376 KB
testcase_37 AC 519 ms
5,376 KB
testcase_38 AC 545 ms
5,376 KB
testcase_39 AC 535 ms
5,376 KB
testcase_40 AC 238 ms
5,376 KB
testcase_41 AC 602 ms
5,376 KB
testcase_42 AC 435 ms
5,376 KB
testcase_43 AC 478 ms
5,376 KB
testcase_44 AC 630 ms
5,376 KB
testcase_45 AC 353 ms
5,376 KB
testcase_46 AC 359 ms
5,376 KB
testcase_47 AC 544 ms
5,376 KB
testcase_48 AC 404 ms
5,376 KB
testcase_49 AC 330 ms
5,376 KB
testcase_50 AC 257 ms
5,376 KB
testcase_51 AC 275 ms
5,376 KB
testcase_52 AC 184 ms
5,376 KB
testcase_53 AC 493 ms
5,376 KB
testcase_54 AC 372 ms
5,376 KB
testcase_55 AC 449 ms
5,376 KB
testcase_56 AC 437 ms
5,376 KB
testcase_57 AC 403 ms
5,376 KB
testcase_58 AC 145 ms
5,376 KB
testcase_59 AC 478 ms
5,376 KB
testcase_60 AC 402 ms
5,376 KB
testcase_61 AC 313 ms
5,376 KB
testcase_62 AC 497 ms
5,376 KB
testcase_63 AC 595 ms
5,376 KB
testcase_64 AC 675 ms
5,376 KB
testcase_65 AC 309 ms
5,376 KB
testcase_66 AC 556 ms
5,376 KB
testcase_67 AC 250 ms
5,376 KB
testcase_68 AC 282 ms
5,376 KB
testcase_69 AC 190 ms
5,376 KB
testcase_70 AC 227 ms
5,376 KB
testcase_71 AC 296 ms
5,376 KB
testcase_72 AC 470 ms
5,376 KB
testcase_73 AC 363 ms
5,376 KB
testcase_74 AC 485 ms
5,376 KB
testcase_75 AC 535 ms
5,376 KB
testcase_76 AC 451 ms
5,376 KB
testcase_77 AC 462 ms
5,376 KB
testcase_78 AC 601 ms
5,376 KB
testcase_79 AC 482 ms
5,376 KB
testcase_80 AC 587 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(int i = 0; i < (int)(n); ++i)
#define rep2(i, n) for(int i = 0; i < (int)(n); ++i)
#define rep3(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep4(i, a, b, c) for(int i = (a); i < (int)(b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define Sort(a) (sort((a).begin(), (a).end()))
#define RSort(a) (sort((a).rbegin(), (a).rend()))
#define UNIQUE(a) (a.erase(unique((a).begin(), (a).end()), (a).end()))

typedef long long int ll;
typedef unsigned long long ul;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef vector<string> vst;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef pair<long long, long long> P;

template<class T> long long sum(const T& a){ return accumulate(a.begin(), a.end(), 0LL); }
template<class T> auto min(const T& a){ return *min_element(a.begin(), a.end()); }
template<class T> auto max(const T& a){ return *max_element(a.begin(), a.end()); }

const long long MINF = 0x7fffffffffff;
const long long INF = 0x1fffffffffffffff;
const long long MOD = 998244353;
const long double EPS = 1e-9;
const long double PI = acos(-1);
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p){ is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){ os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for(T &in : v) is >> in; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v){ for(int i = 0; i < (int) v.size(); ++i){ os << v[i] << (i + 1 != (int) v.size() ? " " : ""); } return os; }
template <typename T, typename S> ostream &operator<<(ostream &os, const map<T, S> &mp){ for(auto &[key, val] : mp){ os << key << ":" << val << " "; } 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() ? " " : ""); itr++; } return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &st){ auto itr = st.begin(); for(int i = 0; i < (int)st.size(); ++i){ os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; }
template <typename T> ostream &operator<<(ostream &os, queue<T> q){ while(q.size()){ os << q.front() << " "; q.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, deque<T> q){ while(q.size()){ os << q.front() << " "; q.pop_front(); } return os; }
template <typename T> ostream &operator<<(ostream &os, stack<T> st){ while(st.size()){ os << st.top() << " "; st.pop(); } return os; }
template <class T, class Container, class Compare> ostream &operator<<(ostream &os, priority_queue<T, Container, Compare> pq){ while(pq.size()){ os << pq.top() << " "; pq.pop(); } return os; }

template<class T, class U> inline T vin(T& vec, U n) { vec.resize(n); for(int i = 0; i < (int) n; ++i) cin >> vec[i]; return vec; }
template<class T> inline void vout(T vec, string s = "\n"){ for(auto x : vec) cout << x << s; }
template<class... T> void in(T&... a){ (cin >> ... >> a); }
void out(){ cout << '\n'; }
template<class T, class... Ts> void out(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
template<class T, class U> void inGraph(vector<vector<T>>& G, U n, U m, bool directed = false){ G.resize(n); for(int i = 0; i < m; ++i){ int a, b; cin >> a >> b; a--, b--; G[a].push_back(b); if(!directed) G[b].push_back(a); } }

template <long long base = 1000000LL, int digit = 6>
struct BigInt{
    int sign = 1;
    vector<long long> val;

    constexpr BigInt(const long long _val = 0) noexcept {
        if(_val != 0){
            val.assign(1, abs(_val));
            shift();
        }
        if(_val < 0) sign = -1;
    }
    constexpr BigInt(const vector<long long> &_val) noexcept : val(_val) {}
    constexpr BigInt(const string &s) noexcept {
        stoi(s);
    }

private:
    void normalize(){
        while(!val.empty() && val.back() == 0) val.pop_back();
        if(val.empty()) sign = 1;
    }
    vector<long long> karatsuba_algorithm(vector<long long> &a, vector<long long> &b){
        const int n = (int) a.size();
        const int h = n >> 1;
        assert(a.size() == b.size());
        assert((n & (n - 1)) == 0);
        if(n <= 64){
            vector<long long> res(2 * n - 1);
            for(int i = 0; i < n; ++i){
                for(int j = 0; j < n; ++j){
                    res[i + j] += a[i] * b[j];
                }
            }
            return res;
        }
        vector<long long> p(h), q(h), r(h), s(h), t(h), u(h);
        for(int i = 0; i < h; ++i){
            p[i] = a[i + h];
            q[i] = a[i];
            r[i] = b[i + h];
            s[i] = b[i];
            t[i] = p[i] + q[i];
            u[i] = r[i] + s[i];
        }
        p = karatsuba_algorithm(p, r);
        q = karatsuba_algorithm(q, s);
        t = karatsuba_algorithm(t, u);
        vector<long long> res(2 * n - 1, 0);
        for(int i = 0; i < n - 1; ++i){
            res[i] += q[i];
            res[i + h] += t[i] - p[i] - q[i];
            res[i + n] += p[i];
        }
        return res;
    }

    pair<BigInt, BigInt> divide_naive(const BigInt& rhs) const {
        assert(!rhs.val.empty());
        const int k = base / (rhs.val.back() + 1);
        const BigInt dividend = (sign == 1 ? *this : -(*this)) * k;
        const BigInt divisor = (rhs.sign == 1 ? rhs : -rhs) * k;
        BigInt quo, rem = 0;
        quo.val.resize(dividend.val.size());
        const int n = divisor.val.size();
        for(int i = (int) dividend.val.size() - 1; i >= 0; --i){
            rem.val.emplace(rem.val.begin(), dividend.val[i]);
            quo.val[i] = ((n < (int) rem.val.size() ? rem.val[n] * base : 0) + ((n - 1) < (int) rem.val.size() ? rem.val[n - 1] : 0)) / divisor.val.back();
            rem -= divisor * quo.val[i];
            while (rem.sign == -1) {
                rem += divisor;
                --quo.val[i];
            }
        }
        quo.sign = sign * rhs.sign;
        quo.normalize();
        rem.sign = sign;
        rem.normalize();
        return {quo, rem / k};
    }

    pair<BigInt, BigInt> divide_newton(const BigInt& rhs) const {
        assert(!rhs.val.empty());
        int preci = val.size() - rhs.val.size();
        BigInt t(1);
        BigInt two = BigInt(2) << rhs.val.size();
        BigInt pre;
        int lim = min(preci, 3);
        int rhslim = min(int(rhs.val.size()), 6);
        t <<= lim;
        while(pre != t){
            BigInt rb = rhs >> (rhs.val.size() - rhslim);
            if(rhslim != (int) rhs.val.size()) rb += BigInt(1);
            pre = t;
            t *= (BigInt(2) << (rhslim + lim)) - rb * t;
            t.val = vector<long long>(t.val.begin() + lim + rhslim, t.val.end());
        }
        if(lim != preci){
            pre = BigInt();
            while(pre != t){
                BigInt rb = rhs >> (rhs.val.size() - rhslim);
                if(rhslim != (int) rhs.val.size()) rb += BigInt(1);
                pre = t;
                t *= (BigInt(2) << (rhslim + lim)) - rb * t;
                t.val = vector<long long>(t.val.begin() + lim + rhslim, t.val.end());
                int next_lim = min(lim * 2 + 1, preci);
                if (next_lim != lim) t <<= next_lim - lim;
                int next_rhslim = min(rhslim * 2 + 1, int(rhs.val.size()));
                lim = next_lim;
                rhslim = next_rhslim;
            }
        }
        BigInt quo = (*this) * t;
        quo.val = vector<long long>(quo.val.begin() + val.size(), quo.val.end());
        BigInt mul = quo * rhs;
        while(mul + rhs <= (*this)){
            quo += BigInt(1);
            mul += rhs;
        }
        BigInt rem = *this - quo * rhs;
        return {quo, rem};
    }

public:
    void stoi(string &s){
        if(s == "0") return;
        int n = s.size(), idx = 0;
        if(s[0] == '-'){
            n -= 1;
            sign = -1;
            idx = 1;
        }
        int len = (n + digit - 1) / digit, rem = n % digit;
        if(rem == 0) rem += digit;
        val.resize(len);
        for(int i = len - 1; i >= 0; --i){
            if(i == len - 1){
                val[i] = stoll(s.substr(idx, rem));
                idx += rem;
            }else{
                val[i] = stoll(s.substr(idx, digit));
                idx += digit;
            }
        }
    }
    string itos() const {
        string res = "";
        if(sign == -1) res += "-";
        bool flag = false;
        for(int i = (int) val.size() - 1; i >= 0; --i){
            if(val[i] > 0 && !flag){
                res += to_string(val[i]);
                flag = true;
            }else if(flag){
                string rem = to_string(val[i]);
                res += string(digit - rem.size(), '0') + rem;
            }
        }
        return (res.empty() || res == "-") ? "0" : res;
    }
    pair<BigInt, BigInt> divide_mod(const BigInt& rhs){
        assert(!rhs.val.empty());
        BigInt div = *this / rhs;
        return make_pair(div, *this - div * rhs);
    }
    BigInt& shift(){
        for(int i = 0; i < (int) val.size() - 1; ++i){
            if(val[i] >= 0){
                val[i + 1] += val[i] / base;
                val[i] %= base;
            }else{
                long long x = (-val[i] + base - 1) / base;
                val[i] += x * base;
                val[i + 1] -= x;
            }
        }
        while(val.back() >= base){
            val.emplace_back(val.back() / base);
            val[val.size() - 2] %= base;
        }
        return *this;
    }
    BigInt& operator=(const BigInt& x) = default;
    inline BigInt& operator+=(const BigInt& rhs) noexcept {
        if(rhs.val.empty()) return *this;
        if(sign != rhs.sign) return *this -= -rhs;
        if(val.size() < rhs.val.size()){
            val.resize(rhs.val.size());
        }
        for(int i = 0; i < (int) rhs.val.size(); ++i){
            val[i] += rhs.val[i];
        }
        return (*this).shift();
    }
    inline BigInt& operator-=(const BigInt& rhs) noexcept {
        if(rhs.val.empty()) return *this;
        if(sign != rhs.sign) return *this += -rhs;
        if((sign == 1 ? *this : -(*this)) < (rhs.sign == 1 ? rhs : -rhs)){
            return *this = -(rhs - *this);
        }
        for(int i = 0; i < (int) rhs.val.size(); ++i){
            val[i] -= rhs.val[i];
        }
        
        shift();
        normalize();
        return *this;
    }
    // Karatsuba Algorithm (O(N^(1.58)))
    inline BigInt& operator*=(const BigInt& rhs) noexcept {
        if(val.empty() || rhs.val.empty()){
            return *this = BigInt();
        }

        sign *= rhs.sign;
        vector<long long> rhsval = rhs.val;
        int k = 1;
        while(k < (int) max(val.size(), rhsval.size())){
            k *= 2;
        }
        val.resize(k), rhsval.resize(k);
        val = karatsuba_algorithm(val, rhsval);

        shift();
        normalize();
        return *this;
    }
    // Newton method
    inline BigInt& operator/=(const BigInt& rhst) noexcept {
        assert(!rhst.val.empty());
        if(val.empty()) return *this;
        if((int) val.size() <= 32 && (int) rhst.val.size() <= 32){
            return *this = divide_naive(rhst).first;
        }

        BigInt rhs = rhst;
        int mulsign = sign * rhs.sign;
        sign = 1, rhs.sign = 1;
        if(*this < rhs){
            return *this = BigInt();
        }

        *this = divide_newton(rhs).first;
        sign = mulsign;
        normalize();
        return *this;
    }
    inline BigInt& operator%=(const BigInt& rhs) noexcept {
        assert(!rhs.val.empty());
        return *this = *this - (*this / rhs) * rhs;
    }
    inline BigInt& operator++() { return *this += 1; }
    inline BigInt operator++(int) {
        const BigInt res = *this;
        ++(*this);
        return res;
    }
    inline BigInt& operator--() { return *this -= 1; }
    inline BigInt operator--(int) {
        const BigInt res = *this;
        --(*this);
        return res;
    }
    inline BigInt operator+() const { return *this; }
    inline BigInt operator-() const {
        BigInt res = *this;
        if (!res.val.empty()) res.sign = -res.sign;
        return res;
    }
    inline BigInt& operator<<=(const unsigned int rhs){
        if(val.back() >= 1 || (int) val.size() >= 2){
            vector<long long> tmp(rhs, 0);
            val.insert(val.begin(), tmp.begin(), tmp.end());
        }
        return *this;
    }
    inline BigInt& operator>>=(const unsigned int rhs){
        if(rhs == 0) return *this;
        if(rhs > val.size()) val = {0};
        else val = vector<long long>(val.begin() + rhs, val.end()); 
        return *this;
    }
    inline bool operator<(const BigInt& rhs) const {
        if(sign != rhs.sign) return sign < rhs.sign;
        if(val.size() != rhs.val.size()) return sign * val.size() < rhs.sign * rhs.val.size();
        for(int i = (int) val.size() - 1; i >= 0; --i){
            if(val[i] != rhs.val[i]) return sign * val[i] < rhs.sign * rhs.val[i];
        }
        return false;
    }
    inline bool operator>(const BigInt& rhs) const { return rhs < (*this); }
    inline bool operator<=(const BigInt& rhs) const { return !((*this) > rhs); }
    inline bool operator>=(const BigInt& rhs) const { return !((*this) < rhs); }
    friend inline BigInt operator+(const BigInt& lhs, const BigInt& rhs) noexcept { return BigInt(lhs) += rhs; }
    friend inline BigInt operator-(const BigInt& lhs, const BigInt& rhs) noexcept { return BigInt(lhs) -= rhs; }
    friend inline BigInt operator*(const BigInt& lhs, const BigInt& rhs) noexcept { return BigInt(lhs) *= rhs; }
    friend inline BigInt operator/(const BigInt& lhs, const BigInt& rhs) noexcept { return BigInt(lhs) /= rhs; }
    friend inline BigInt operator%(const BigInt& lhs, const BigInt& rhs) noexcept { return BigInt(lhs) %= rhs; }
    friend inline BigInt operator<<(const BigInt& lhs, const unsigned int rhs) noexcept { return BigInt(lhs) <<= rhs; }
    friend inline BigInt operator>>(const BigInt& lhs, const unsigned int rhs) noexcept { return BigInt(lhs) >>= rhs; }
    friend inline bool operator==(const BigInt& lhs, const BigInt& rhs) noexcept { return lhs.val == rhs.val; }
    friend inline bool operator!=(const BigInt& lhs, const BigInt& rhs) noexcept { return lhs.val != rhs.val; }
    friend inline istream& operator>>(istream& is, BigInt& x) noexcept {
        string s;
        is >> s;
        x.stoi(s);
        return is;
    }
    friend inline ostream& operator<<(ostream& os, const BigInt& x) noexcept { return os << x.itos(); }
};

using bint = BigInt<1000000LL, 6>;

struct fraction{
    bint p, q;
    fraction(bint P = 0, bint Q = 1): p(P), q(Q){ }
    inline bool operator==(const fraction &other) const {
        return p * other.q == other.p * q;
    }
    inline bool operator!=(const fraction &other) const {
        return p * other.q != other.p * q;
    }
    inline bool operator<(const fraction &other) const {
        return p * other.q < other.p * q;
    }
    inline bool operator<=(const fraction &other) const {
        return p * other.q <= other.p * q;
    }
    inline bool operator>(const fraction &other) const {
        return p * other.q > other.p * q;
    }
    inline bool operator>=(const fraction &other) const {
        return p * other.q >= other.p * q;
    }
    inline fraction operator+(const fraction &other) const { return fraction(p * other.q + q * other.p, q * other.q); }
    inline fraction operator-(const fraction &other) const { return fraction(p * other.q - q * other.p, q * other.q); }
    inline fraction operator*(const fraction &other) const { return fraction(p * other.p, q * other.q); }
    inline fraction operator/(const fraction &other) const { return fraction(p * other.q, q * other.p); }
    inline fraction& operator+=(const fraction& rhs) noexcept {
        *this = *this + rhs;
        return *this;
    }
    inline fraction& operator-=(const fraction& rhs) noexcept {
        *this = *this - rhs;
        return *this;
    }
    inline fraction& operator*=(const fraction& rhs) noexcept {
        *this = *this * rhs;
        return *this;
    }
    inline fraction& operator/=(const fraction& rhs) noexcept {
        *this = *this / rhs;
        return *this;
    }
    friend inline istream& operator>>(istream& is, fraction& x) noexcept {
        is >> x.p;
        x.q = 1;
        return is;
    }
    friend inline ostream& operator<<(ostream& os, const fraction& x) noexcept { return os << x.p << "/" << x.q; }
};

void input(){
}

using Point = pair<fraction, fraction>;

fraction dist(Point p, Point q){
    return (p.first - q.first) * (p.first - q.first) + (p.second - q.second) * (p.second - q.second);
}

void solve(){
    ll q;
    bint x1, y1, x2, y2, x3, y3;
    in(q);
    in(x1, y1, x2, y2, x3, y3);

    vector<pair<bint, bint>> xy(3);
    xy[0] = {x1, y1}, xy[1] = {x2, y2}, xy[2] = {x3, y3};
    Sort(xy);

    Point p;
    if((x1 - x2) * (y1 - y3) - (x1 - x3) * (y1 - y2) == 0){
        fraction x_p(xy[0].first + xy[2].first, 2);
        fraction y_p(xy[0].second + xy[2].second, 2);
        p = {x_p, y_p};
    }else{
        fraction x_p((y1 - y2) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1) - (y1 - y3) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1), 2 * (x1 - x2) * (y1 - y3) - 2 * (x1 - x3) * (y1 - y2));
        fraction y_p((x1 - x3) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1) - (x1 - x2) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1), 2 * (x1 - x2) * (y1 - y3) - 2 * (x1 - x3) * (y1 - y2));
        p = {x_p, y_p};
    }

    Point a = {fraction(x1, 1), fraction(y1, 1)}, b = {fraction(x2, 1), fraction(y2, 1)}, c = {fraction(x3, 1), fraction(y3, 1)};
    fraction r = dist(p, a);
    chmax(r, dist(p, b));
    chmax(r, dist(p, c));
    while(q--){
        fraction x, y; in(x, y);
        Point q = {x, y};
        if(dist(p, q) <= r){
            out("Yes");
        }else{
            out("No");
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);
    
    input();
    solve();
}
0