結果
問題 | No.2602 Real Collider |
ユーザー | iiljj |
提出日時 | 2024-01-27 13:41:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 27,357 bytes |
コンパイル時間 | 8,717 ms |
コンパイル使用メモリ | 406,884 KB |
実行使用メモリ | 15,796 KB |
最終ジャッジ日時 | 2024-09-28 09:36:46 |
合計ジャッジ時間 | 29,994 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 715 ms
15,796 KB |
testcase_11 | AC | 266 ms
7,808 KB |
testcase_12 | AC | 152 ms
9,048 KB |
testcase_13 | AC | 73 ms
6,940 KB |
testcase_14 | AC | 169 ms
9,548 KB |
testcase_15 | AC | 211 ms
6,940 KB |
testcase_16 | AC | 321 ms
8,448 KB |
testcase_17 | AC | 357 ms
8,988 KB |
testcase_18 | AC | 103 ms
7,392 KB |
testcase_19 | AC | 129 ms
8,200 KB |
testcase_20 | AC | 370 ms
10,208 KB |
testcase_21 | AC | 106 ms
7,168 KB |
testcase_22 | AC | 123 ms
8,052 KB |
testcase_23 | AC | 82 ms
6,940 KB |
testcase_24 | AC | 122 ms
7,680 KB |
testcase_25 | AC | 126 ms
8,072 KB |
testcase_26 | AC | 179 ms
6,940 KB |
testcase_27 | AC | 147 ms
8,704 KB |
testcase_28 | AC | 289 ms
8,900 KB |
testcase_29 | AC | 125 ms
7,936 KB |
testcase_30 | AC | 138 ms
8,192 KB |
testcase_31 | AC | 343 ms
8,576 KB |
testcase_32 | AC | 275 ms
7,808 KB |
testcase_33 | WA | - |
testcase_34 | AC | 302 ms
8,656 KB |
testcase_35 | AC | 210 ms
6,940 KB |
testcase_36 | AC | 168 ms
6,940 KB |
testcase_37 | AC | 378 ms
9,128 KB |
testcase_38 | AC | 360 ms
9,136 KB |
testcase_39 | AC | 380 ms
9,044 KB |
testcase_40 | AC | 172 ms
6,944 KB |
testcase_41 | AC | 407 ms
9,724 KB |
testcase_42 | AC | 310 ms
8,320 KB |
testcase_43 | AC | 281 ms
8,568 KB |
testcase_44 | AC | 429 ms
9,820 KB |
testcase_45 | AC | 241 ms
7,424 KB |
testcase_46 | AC | 249 ms
7,168 KB |
testcase_47 | AC | 366 ms
9,012 KB |
testcase_48 | AC | 277 ms
7,680 KB |
testcase_49 | AC | 248 ms
7,040 KB |
testcase_50 | AC | 181 ms
6,940 KB |
testcase_51 | AC | 196 ms
6,940 KB |
testcase_52 | AC | 127 ms
6,940 KB |
testcase_53 | AC | 342 ms
8,532 KB |
testcase_54 | AC | 256 ms
7,524 KB |
testcase_55 | AC | 283 ms
7,936 KB |
testcase_56 | AC | 289 ms
7,776 KB |
testcase_57 | AC | 264 ms
7,552 KB |
testcase_58 | AC | 93 ms
6,940 KB |
testcase_59 | WA | - |
testcase_60 | AC | 243 ms
7,936 KB |
testcase_61 | AC | 204 ms
6,944 KB |
testcase_62 | AC | 323 ms
8,660 KB |
testcase_63 | AC | 354 ms
9,288 KB |
testcase_64 | AC | 458 ms
10,396 KB |
testcase_65 | AC | 207 ms
6,944 KB |
testcase_66 | AC | 362 ms
9,044 KB |
testcase_67 | AC | 151 ms
6,940 KB |
testcase_68 | AC | 179 ms
6,940 KB |
testcase_69 | AC | 117 ms
6,944 KB |
testcase_70 | AC | 147 ms
6,944 KB |
testcase_71 | AC | 213 ms
6,944 KB |
testcase_72 | AC | 324 ms
8,448 KB |
testcase_73 | AC | 264 ms
7,552 KB |
testcase_74 | AC | 347 ms
8,564 KB |
testcase_75 | AC | 348 ms
8,960 KB |
testcase_76 | AC | 318 ms
8,304 KB |
testcase_77 | AC | 322 ms
8,436 KB |
testcase_78 | AC | 414 ms
9,764 KB |
testcase_79 | AC | 315 ms
8,812 KB |
testcase_80 | AC | 368 ms
9,604 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 __int128_t */ // output std::ostream &operator<<(std::ostream &dest, const __int128_t value) { std::ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } const int len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest; } // string to __int128_t __int128_t parse(const string &s) { __int128_t ret = 0; for (int i = 0; i < (int)s.length(); ++i) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret; } 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 <> struct std::hash<__int128_t> { // public: // // クラスのメンバの値それぞれについてハッシュ生成して、それらを結合して一つのハッシュ値にする // size_t operator()(const __int128_t &data) const { // std::size_t seed = 0; // hash_combine(seed, (unsigned long long)data); // hash_combine(seed, (unsigned long long)(data >> 64)); // return seed; // } // }; /* #endregion */ /* #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 = 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 > 0 && right > 0) || (left < 0 && right < 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 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 */ template <typename T> RationalNum<T> testpow(RationalNum<T> a, ll t) { RationalNum<T> res = 1; while (t) { dump(t, t & 1); if (t & 1) res *= a; t >>= 1; if (t == 0) break; a *= a; } return res; } int mybitlen(__int128_t v) { int ret = 0; while (v != 0) { v >>= 1; ++ret; } return ret; } template <typename T> bool testoperator(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 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 } dump(111, mybitlen(left.numerator), mybitlen(right.denominator)); __int128_t lside128 = __int128_t(left.numerator) * right.denominator; dump(222); __int128_t rside128 = __int128_t(left.denominator) * right.numerator; dump(333); return (lside128 < rside128); } // Problem void solve() { // using mi = mp::cpp_int; // using T = mi; using T = __int128_t; 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]) / 2; Rat cy = (Y[i] + Y[(i + 1) % 3]) / 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 / 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 / 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]) / 2; cy = (Y[diameter_idx] + Y[(diameter_idx + 1) % 3]) / 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; }