結果
問題 | No.2602 Real Collider |
ユーザー | iiljj |
提出日時 | 2024-01-27 15:13:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 25,918 bytes |
コンパイル時間 | 7,316 ms |
コンパイル使用メモリ | 422,368 KB |
実行使用メモリ | 28,416 KB |
最終ジャッジ日時 | 2024-09-28 09:41:13 |
合計ジャッジ時間 | 66,108 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 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 | TLE | - |
testcase_11 | AC | 811 ms
12,288 KB |
testcase_12 | AC | 395 ms
14,848 KB |
testcase_13 | AC | 209 ms
8,852 KB |
testcase_14 | AC | 445 ms
15,872 KB |
testcase_15 | AC | 653 ms
10,060 KB |
testcase_16 | AC | 1,010 ms
13,820 KB |
testcase_17 | AC | 1,129 ms
14,816 KB |
testcase_18 | AC | 281 ms
11,520 KB |
testcase_19 | AC | 363 ms
13,212 KB |
testcase_20 | AC | 1,126 ms
17,084 KB |
testcase_21 | AC | 277 ms
11,008 KB |
testcase_22 | AC | 319 ms
12,788 KB |
testcase_23 | AC | 213 ms
9,624 KB |
testcase_24 | AC | 319 ms
12,288 KB |
testcase_25 | AC | 345 ms
12,800 KB |
testcase_26 | AC | 497 ms
10,160 KB |
testcase_27 | AC | 386 ms
14,208 KB |
testcase_28 | AC | 850 ms
14,592 KB |
testcase_29 | AC | 333 ms
12,604 KB |
testcase_30 | AC | 378 ms
13,440 KB |
testcase_31 | AC | 1,048 ms
13,908 KB |
testcase_32 | AC | 828 ms
12,276 KB |
testcase_33 | AC | 1,097 ms
13,896 KB |
testcase_34 | AC | 938 ms
13,940 KB |
testcase_35 | AC | 680 ms
9,860 KB |
testcase_36 | AC | 492 ms
9,880 KB |
testcase_37 | AC | 1,184 ms
14,720 KB |
testcase_38 | AC | 1,179 ms
15,104 KB |
testcase_39 | AC | 1,111 ms
14,720 KB |
testcase_40 | AC | 545 ms
8,820 KB |
testcase_41 | AC | 1,225 ms
16,380 KB |
testcase_42 | AC | 950 ms
13,440 KB |
testcase_43 | AC | 804 ms
13,568 KB |
testcase_44 | AC | 1,301 ms
16,552 KB |
testcase_45 | AC | 743 ms
11,508 KB |
testcase_46 | AC | 779 ms
11,052 KB |
testcase_47 | AC | 1,146 ms
15,128 KB |
testcase_48 | AC | 882 ms
12,136 KB |
testcase_49 | AC | 780 ms
10,904 KB |
testcase_50 | AC | 533 ms
9,048 KB |
testcase_51 | AC | 569 ms
9,660 KB |
testcase_52 | AC | 377 ms
7,680 KB |
testcase_53 | AC | 1,127 ms
13,972 KB |
testcase_54 | AC | 749 ms
11,604 KB |
testcase_55 | AC | 866 ms
12,632 KB |
testcase_56 | AC | 843 ms
12,352 KB |
testcase_57 | AC | 774 ms
11,860 KB |
testcase_58 | AC | 286 ms
6,940 KB |
testcase_59 | AC | 1,048 ms
13,596 KB |
testcase_60 | AC | 711 ms
12,544 KB |
testcase_61 | AC | 659 ms
10,480 KB |
testcase_62 | AC | 1,043 ms
14,252 KB |
testcase_63 | AC | 1,070 ms
15,708 KB |
testcase_64 | AC | 1,388 ms
17,488 KB |
testcase_65 | AC | 617 ms
10,328 KB |
testcase_66 | AC | 1,061 ms
14,868 KB |
testcase_67 | AC | 501 ms
8,636 KB |
testcase_68 | AC | 577 ms
9,500 KB |
testcase_69 | AC | 373 ms
7,600 KB |
testcase_70 | AC | 484 ms
8,704 KB |
testcase_71 | AC | 695 ms
10,072 KB |
testcase_72 | AC | 947 ms
13,732 KB |
testcase_73 | AC | 863 ms
11,828 KB |
testcase_74 | AC | 1,086 ms
13,904 KB |
testcase_75 | AC | 1,145 ms
14,840 KB |
testcase_76 | AC | 943 ms
13,108 KB |
testcase_77 | AC | 992 ms
13,588 KB |
testcase_78 | AC | 1,246 ms
16,112 KB |
testcase_79 | AC | 1,030 ms
14,348 KB |
testcase_80 | AC | 1,159 ms
16,164 KB |
ソースコード
/* #region Head */ // #include <bits/stdc++.h> #include <algorithm> #include <array> #include <bitset> #include <cassert> // assert.h #include <cmath> // math.h #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pll = pair<ll, ll>; template <class T> using vc = vector<T>; template <class T> using vvc = vc<vc<T>>; using vll = vc<ll>; using vvll = vvc<ll>; using vld = vc<ld>; using vvld = vvc<ld>; using vs = vc<string>; using vvs = vvc<string>; template <class T, class U> using um = unordered_map<T, U>; template <class T> using pq = priority_queue<T>; template <class T> using pqa = priority_queue<T, vc<T>, greater<T>>; template <class T> using us = unordered_set<T>; #define TREP(T, i, m, n) for (T i = (m), i##_len = (T)(n); i < i##_len; ++(i)) #define TREPM(T, i, m, n) for (T i = (m), i##_max = (T)(n); i <= i##_max; ++(i)) #define TREPR(T, i, m, n) for (T i = (m), i##_min = (T)(n); i >= i##_min; --(i)) #define TREPD(T, i, m, n, d) for (T i = (m), i##_len = (T)(n); i < i##_len; i += (d)) #define TREPMD(T, i, m, n, d) for (T i = (m), i##_max = (T)(n); i <= i##_max; i += (d)) #define REP(i, m, n) for (ll i = (m), i##_len = (ll)(n); i < i##_len; ++(i)) #define REPM(i, m, n) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; ++(i)) #define REPR(i, m, n) for (ll i = (m), i##_min = (ll)(n); i >= i##_min; --(i)) #define REPD(i, m, n, d) for (ll i = (m), i##_len = (ll)(n); i < i##_len; i += (d)) #define REPMD(i, m, n, d) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; i += (d)) #define REPI(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define REPIR(itr, ds) for (auto itr = ds.rbegin(); itr != ds.rend(); itr++) #define ALL(x) begin(x), end(x) #define SIZE(x) ((ll)(x).size()) #define ISIZE(x) ((int)(x).size()) #define PERM(c) \ sort(ALL(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c))) #define UNIQ(v) v.erase(unique(ALL(v)), v.end()); #define CEIL(a, b) (((a) + (b)-1) / (b)) #define endl '\n' constexpr ll INF = 1'010'000'000'000'000'017LL; constexpr int IINF = 1'000'000'007LL; constexpr ll MOD = 1'000'000'007LL; // 1e9 + 7 // constexpr ll MOD = 998244353; constexpr ld EPS = 1e-12; constexpr ld PI = 3.14159265358979323846; template <typename T> istream &operator>>(istream &is, vc<T> &vec) { // vector 入力 for (T &x : vec) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vc<T> &vec) { // vector 出力 (for dump) os << "{"; REP(i, 0, SIZE(vec)) os << vec[i] << (i == i_len - 1 ? "" : ", "); os << "}"; return os; } template <typename T> ostream &operator>>(ostream &os, const vc<T> &vec) { // vector 出力 (inline) REP(i, 0, SIZE(vec)) os << vec[i] << (i == i_len - 1 ? "\n" : " "); return os; } template <typename T, size_t _Nm> istream &operator>>(istream &is, array<T, _Nm> &arr) { // array 入力 REP(i, 0, SIZE(arr)) is >> arr[i]; return is; } template <typename T, size_t _Nm> ostream &operator<<(ostream &os, const array<T, _Nm> &arr) { // array 出力 (for dump) os << "{"; REP(i, 0, SIZE(arr)) os << arr[i] << (i == i_len - 1 ? "" : ", "); os << "}"; return os; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &pair_var) { // pair 入力 is >> pair_var.first >> pair_var.second; return is; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &pair_var) { // pair 出力 os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // map, um, set, us 出力 template <class T> ostream &out_iter(ostream &os, const T &map_var) { os << "{"; REPI(itr, map_var) { os << *itr; auto itrcp = itr; if (++itrcp != map_var.end()) os << ", "; } return os << "}"; } template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &map_var) { return out_iter(os, map_var); } template <typename T, typename U> ostream &operator<<(ostream &os, const um<T, U> &map_var) { os << "{"; REPI(itr, map_var) { auto [key, value] = *itr; os << "(" << key << ", " << value << ")"; auto itrcp = itr; if (++itrcp != map_var.end()) os << ", "; } os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) { return out_iter(os, set_var); } template <typename T> ostream &operator<<(ostream &os, const us<T> &set_var) { return out_iter(os, set_var); } template <typename T> ostream &operator<<(ostream &os, const pq<T> &pq_var) { pq<T> pq_cp(pq_var); os << "{"; if (!pq_cp.empty()) { os << pq_cp.top(), pq_cp.pop(); while (!pq_cp.empty()) os << ", " << pq_cp.top(), pq_cp.pop(); } return os << "}"; } // tuple 出力 template <size_t N = 0, bool end_line = false, typename... Args> ostream &operator<<(ostream &os, tuple<Args...> &a) { if constexpr (N < std::tuple_size_v<tuple<Args...>>) { os << get<N>(a); if constexpr (N + 1 < std::tuple_size_v<tuple<Args...>>) { os << ' '; } else if constexpr (end_line) { os << '\n'; } return operator<< <N + 1, end_line>(os, a); } return os; } template <typename... Args> void print_tuple(tuple<Args...> &a) { operator<< <0, true>(std::cout, a); } void pprint() { std::cout << endl; } template <class Head, class... Tail> void pprint(Head &&head, Tail &&...tail) { std::cout << head; if (sizeof...(Tail) > 0) std::cout << ' '; pprint(move(tail)...); } // dump #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) DUMPOUT << ", "; dump_func(move(tail)...); } // chmax (更新「される」かもしれない値が前) template <typename T, typename U, typename Comp = less<>> bool chmax(T &xmax, const U &x, Comp comp = {}) { if (comp(xmax, x)) { xmax = x; return true; } return false; } // chmin (更新「される」かもしれない値が前) template <typename T, typename U, typename Comp = less<>> bool chmin(T &xmin, const U &x, Comp comp = {}) { if (comp(x, xmin)) { xmin = x; return true; } return false; } // ローカル用 #ifndef ONLINE_JUDGE #define DEBUG_ #endif #ifndef MYLOCAL #undef DEBUG_ #endif #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif #define VAR(type, ...) \ type __VA_ARGS__; \ assert((std::cin >> __VA_ARGS__)); template <typename T> istream &operator,(istream &is, T &rhs) { return is >> rhs; } template <typename T> ostream &operator,(ostream &os, const T &rhs) { return os << ' ' << rhs; } struct AtCoderInitialize { static constexpr int IOS_PREC = 15; static constexpr bool AUTOFLUSH = false; AtCoderInitialize() { ios_base::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr); std::cout << fixed << setprecision(IOS_PREC); if (AUTOFLUSH) std::cout << unitbuf; } } ATCODER_INITIALIZE; void Yn(bool p) { std::cout << (p ? "Yes" : "No") << endl; } void YN(bool p) { std::cout << (p ? "YES" : "NO") << endl; } template <typename T> constexpr void operator--(vc<T> &v, int) noexcept { for (int i = 0; i < ISIZE(v); ++i) v[i]--; } template <typename T> constexpr void operator++(vc<T> &v, int) noexcept { for (int i = 0; i < ISIZE(v); ++i) v[i]++; } /* #endregion */ // #include <atcoder/all> // using namespace atcoder; #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; /* #region Rational */ template <typename T> struct RationalNum { // 分子 T numerator; // 分母 T denominator; RationalNum() { numerator = 0, denominator = 1; } // RationalNum(double x); RationalNum(T numerator_, T denominator_ = 1) { numerator = numerator_, denominator = denominator_; simplify(); } // 自身を簡約する void simplify() { RationalNum<T>::simplifyNums(numerator, denominator); } static T mygcd(const T &a, const T &b) { // std::gcd が使える場合 if constexpr ((std::is_integral<T>::value)) { return std::gcd(a, b); } // std::gcd が使えない場合 (__int128_t など) if (b == 0) { return a; } else { return mygcd(b, a % b); } } static void simplifyNums(T &numerator_, T &denominator_) { if (denominator_ == 0) { // 分母が 0 のときの正規化 if (numerator_ > 0) numerator_ = 1; // 無限大 else if (numerator_ < 0) numerator_ = -1; // 無限小 else numerator_ = 0; // 不定 } else { T g = mygcd(numerator_, denominator_); numerator_ /= g, denominator_ /= g; if (denominator_ < 0) numerator_ *= -1, denominator_ *= -1; } } // 逆数を返す. RationalNum<T> inv() const { return RationalNum<T>(denominator, numerator); } // t 乗を返す. RationalNum<T> pow(ll t) const { RationalNum<T> a(*this); RationalNum<T> res = T(1); while (t) { if (t & 1) res *= a; t >>= 1; if (t == 0) break; a *= a; } return res; } // 小数点以下を切り上げた整数を返す T ceil() const { if (numerator >= 0) return (numerator + denominator - 1) / denominator; else return numerator / denominator; } // 小数点以下を切り捨てた整数を返す T floor() const { if (numerator >= 0) return numerator / denominator; else return (numerator - denominator + 1) / denominator; } // operator ll() const { return floor(); } // member function RationalNum<T> &operator+=(const RationalNum<T> &obj) { return *this = *this + obj; } RationalNum<T> &operator-=(const RationalNum<T> &obj) { return *this = *this - obj; } RationalNum<T> &operator*=(const RationalNum<T> &obj) { return *this = *this * obj; } RationalNum<T> &operator/=(const RationalNum<T> &obj) { return *this = *this / obj; } RationalNum<T> &operator++() { return *this = *this + 1; } RationalNum<T> operator++(int) { RationalNum<T> before = *this; *this = *this + 1; return before; } RationalNum<T> &operator--() { return *this = *this - 1; } RationalNum<T> operator--(int) { RationalNum<T> before = *this; *this = *this - 1; return before; } RationalNum<T> operator+() const { return *this; } RationalNum<T> operator-() const { return RationalNum<T>(-numerator, denominator); } // friend functions friend RationalNum<T> operator+(const RationalNum<T> &left, const RationalNum<T> &right) { if (left.denominator == 0 && right.denominator == 0) { if (left.numerator == 0) return left; // left が不定 if (right.numerator == 0) return right; // right が不定 if ((left > T(0) && right > T(0)) || (left < T(0) && right < T(0))) { return left; // 無限大・無限小 } else { return RationalNum<T>(0, 0); // 不定 } } else if (left.denominator == 0) { return left; } else if (right.denominator == 0) { return right; } RationalNum<T> temp; T tempLD = left.denominator; T tempRD = right.denominator; RationalNum<T>::simplifyNums(tempLD, tempRD); temp.denominator = left.denominator * tempRD; temp.numerator = left.numerator * tempRD + right.numerator * tempLD; temp.simplify(); return temp; } friend RationalNum<T> operator-(const RationalNum<T> &left, const RationalNum<T> &right) { return left + (-right); // } friend RationalNum<T> operator*(const RationalNum<T> &left, const RationalNum<T> &right) { T a = left.denominator, b = right.numerator, c = right.denominator, d = left.numerator; RationalNum<T>::simplifyNums(b, a), RationalNum<T>::simplifyNums(d, c); return RationalNum<T>(b * d, a * c); } friend RationalNum<T> operator/(const RationalNum<T> &left, const RationalNum<T> &right) { return left * right.inv(); // } friend bool operator==(const RationalNum<T> &left, const RationalNum<T> &right) { return (left.numerator == right.numerator && left.denominator == right.denominator); } friend bool operator!=(const RationalNum<T> &left, const RationalNum<T> &right) { return !(left == right); // } friend bool operator<(const RationalNum<T> &left, const RationalNum<T> &right) { RationalNum<T> indeterminate(0, 0); if (left == indeterminate || right == indeterminate) { // どちらかが不定のときは大小を正しく計算できないので,特別扱いする // 便宜上,不定は「無限大より大きい」として扱う if (right != indeterminate) { return false; } else if (left != indeterminate) { return true; } else { return false; } } // 符号が異なるときはすぐ判定できる if (left.numerator < 0 && right.numerator >= 0) return true; if (left.numerator <= 0 && right.numerator > 0) return true; if (left.numerator > 0 && right.numerator <= 0) return false; if (left.numerator >= 0 && right.numerator < 0) return false; // 両方 0 の場合 if (left.numerator == 0 && right.numerator == 0) return false; // 分母が等しい場合 if (left.denominator == right.denominator) { return left.numerator < right.numerator; } // 分子が等しい場合(通分しないで済むなら嬉しいので)(若干高速化できる) if (left.numerator == right.numerator) { if (left.numerator > 0) { // 正の数→分母が大きいほど分数としては小さい return left.denominator > right.denominator; } else { // 負の数→分母が大きいほど分数としても大きい return left.denominator < right.denominator; } } // 整数に丸めて比較可能ならそうする(若干高速化できる) if (left.numerator > 0) { assert(right.numerator > 0); const T q_left = left.floor(); const T q_right = right.floor(); if (q_left != q_right) { return q_left < q_right; } } else { assert(left.numerator < 0); assert(right.numerator < 0); const T q_left = left.ceil(); const T q_right = right.ceil(); if (q_left != q_right) { return q_left < q_right; } } // ジャッジサーバでは __int128_t でも is_integral == true になるので, // この分岐は使わない // if constexpr ((std::is_integral<T>::value)) { // ll lside; // bool of0 = __builtin_mul_overflow(left.numerator, right.denominator, &lside); // // = left.numerator * right.denominator; // ll rside; // bool of1 = __builtin_mul_overflow(left.denominator, right.numerator, &rside); // // left.denominator * right.numerator; // if (!of0 && !of1) return (lside < rside); // 両方ok // __int128_t lside128 = __int128_t(left.numerator) * right.denominator; // __int128_t rside128 = __int128_t(left.denominator) * right.numerator; // return (lside128 < rside128); // } RationalNum<T> diff = right - left; return diff.numerator > 0; } // // 積が ll を超えることもあるので,map のキーで使うとかのときは, // // 異なる RationalNum の間に必ず大小関係が定義できる(ただし分数の大小とは異なる)こちらを使う? // friend bool operator<(const RationalNum &left, const RationalNum &right) { // return left.numerator == right.numerator ? left.denominator < right.denominator : left.numerator < // right.numerator; // } friend bool operator>(const RationalNum<T> &left, const RationalNum<T> &right) { // ll lside = left.getNumerator() * right.getDenominator(); // ll rside = left.getDenominator() * right.getNumerator(); // return (lside > rside); return !(left < right) && (left != right); } friend bool operator<=(const RationalNum<T> &left, const RationalNum<T> &right) { return ((left < right) || (left == right)); } friend bool operator>=(const RationalNum<T> &left, const RationalNum<T> &right) { return ((left > right) || (left == right)); } // 出力 friend ostream &operator<<(ostream &out, const RationalNum<T> &obj) { if (obj.denominator == 0) { if (obj.numerator > 0) out << "inf"; else if (obj.numerator < 0) out << "-inf"; else out << "indeterminate"; } else { out << obj.numerator; if (obj.numerator != 0 && obj.denominator != 1) out << "/" << obj.denominator; } return out; } // 小数の入力には使っても問題なさそう // https://atcoder.jp/contests/abc169/tasks/abc169_c // 入力 friend istream &operator>>(istream &in, RationalNum<T> &obj) { string inputstr; T num = 0; int sign = 1; bool slashExist = false; bool dotExist = false; // bool validInput = true; T virtualDenominator = 1; cin >> inputstr; REP(i, 0, SIZE(inputstr)) { char temp = inputstr[i]; if (temp == '.') { if (dotExist == false && slashExist == false && i != 0) { dotExist = true; } // else { // validInput = false; // break; // } } else if (temp == '/') { if (dotExist == false && slashExist == false && i != 0) { slashExist = true; obj.numerator = (sign * num); num = 0; sign = 1; } // else { // validInput = false; // break; // } } else if (temp == '-') { if (i == 0) { sign = -sign; } else if (inputstr[i - 1] == '/') { sign = -sign; } // else { // validInput = false; // break; // } } else if (temp <= '9' && temp >= '0') { if (dotExist) { // if (virtualDenominator > INF / 10) { // cerr << "this frational is too long to handle."; // validInput = false; // break; // } else virtualDenominator *= 10; } // if (num > INF / 10) { // cerr << "this number is too long to handle."; // validInput = false; // break; // } num *= 10; num += inputstr[i] - '0'; } // else { // validInput = false; // break; // } } // if (validInput == false) { // obj.numerator = (0); // obj.denominator = (1); // cerr << "Input is not valid! The whole set to 0" << endl; // } if (slashExist == true) { obj.denominator = (sign * num); } else if (dotExist) { obj.numerator = (sign * num); obj.denominator = (virtualDenominator); } else { obj.numerator = (sign * num); obj.denominator = (1); } obj.simplify(); return in; } }; // __int128_t を使わない場合はアンコメントする // template <typename T> void hash_combine(size_t &seed, T const &v) { // // 基本型に関するハッシュ生成は標準ライブラリが提供している // std::hash<T> primitive_type_hash; // // 生成したハッシュを合成する。このコードはboostものを使用する // seed ^= primitive_type_hash(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); // } template <typename T> struct std::hash<RationalNum<T>> { public: // クラスのメンバの値それぞれについてハッシュ生成して、それらを結合して一つのハッシュ値にする size_t operator()(const RationalNum<T> &data) const { std::size_t seed = 0; hash_combine(seed, data.numerator); hash_combine(seed, data.denominator); return seed; } }; /* #endregion */ // Problem void solve() { using mi = mp::cpp_int; using T = mi; using Rat = RationalNum<T>; VAR(ll, q); // VAR(ll, xa, ya, xb, yb, xc, yc); // dump(q); vc<Rat> X(3), Y(3); REP(i, 0, 3) cin >> X[i], Y[i]; vc<Rat> x(q), y(q); REP(i, 0, q) cin >> x[i], y[i]; // dump(X, Y, x, y); // dump(X, Y); // パターンとして,次の2通りのいずれかを判定する // 1. ある2点を結ぶ線分が直径になっている円 // 2. 3点を通る円 ll diameter_idx = -1; REP(i, 0, 3) { // [i]-[i+1] の線分が直径である円は,[i+2] を内部または周上に含むか? Rat cx = (X[i] + X[(i + 1) % 3]) / T(2); Rat cy = (Y[i] + Y[(i + 1) % 3]) / T(2); // 円の半径^2 Rat r2 = (X[i] - cx).pow(2) + (Y[i] - cy).pow(2); // 中心からの距離^2 Rat d2 = (X[(i + 2) % 3] - cx).pow(2) + (Y[(i + 2) % 3] - cy).pow(2); if (d2 <= r2) { diameter_idx = i; break; } } // dump(diameter_idx); Rat cx, cy, r2; if (diameter_idx == -1) { // 3点を通る円の外心 // https://w3e.kanazawa-it.ac.jp/math/category/kika/heimenkika/henkan-tex.cgi?target=/math/category/kika/heimenkika/gaisinn_motomekata.html // x 座標 const Rat cx_num = (X[0].pow(2) + Y[0].pow(2)) * (Y[1] - Y[2]) + // (X[1].pow(2) + Y[1].pow(2)) * (Y[2] - Y[0]) + // (X[2].pow(2) + Y[2].pow(2)) * (Y[0] - Y[1]); const Rat cx_den = (X[0] - X[1]) * (Y[1] - Y[2]) - // (X[1] - X[2]) * (Y[0] - Y[1]); cx = cx_num / cx_den / T(2); // dump(cx); // y 座標 const Rat cy_num = (X[0].pow(2) + Y[0].pow(2)) * (X[1] - X[2]) + // (X[1].pow(2) + Y[1].pow(2)) * (X[2] - X[0]) + // (X[2].pow(2) + Y[2].pow(2)) * (X[0] - X[1]); const Rat cy_den = (X[1] - X[2]) * (Y[0] - Y[1]) - // (X[0] - X[1]) * (Y[1] - Y[2]); cy = cy_num / cy_den / T(2); // dump(cy); // 半径 const Rat dx = cx - X[0]; const Rat dy = cy - Y[0]; // dump(dx, dy); // dump(testpow(dx, 2)); // dump(testpow(dy, 2)); r2 = dx.pow(2) + dy.pow(2); // dump(cx, cy, r2); } else { // 2点を結ぶ線分を直径とする円 cx = (X[diameter_idx] + X[(diameter_idx + 1) % 3]) / T(2); cy = (Y[diameter_idx] + Y[(diameter_idx + 1) % 3]) / T(2); r2 = (X[diameter_idx] - cx).pow(2) + (Y[diameter_idx] - cy).pow(2); // dump(cx, cy, r2); } REP(i, 0, q) { // dump(i); // dump(x[i] - cx); // dump(y[i] - cy); // dump((x[i] - cx).pow(2)); // dump((y[i] - cy).pow(2)); Rat d2 = (x[i] - cx).pow(2) + (y[i] - cy).pow(2); // dump(d2, r2); // dump(d2 - r2); // dump(testoperator(d2, r2)); Yn(d2 <= r2); } } // entry point int main() { solve(); return 0; }