結果
問題 | No.2602 Real Collider |
ユーザー | iiljj |
提出日時 | 2024-01-12 22:50:47 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 24,965 bytes |
コンパイル時間 | 2,583 ms |
コンパイル使用メモリ | 164,768 KB |
実行使用メモリ | 15,716 KB |
最終ジャッジ日時 | 2024-09-27 23:37:21 |
合計ジャッジ時間 | 35,313 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,948 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 1,089 ms
15,716 KB |
testcase_11 | AC | 438 ms
7,808 KB |
testcase_12 | AC | 205 ms
8,960 KB |
testcase_13 | AC | 101 ms
6,944 KB |
testcase_14 | AC | 223 ms
9,496 KB |
testcase_15 | AC | 349 ms
6,940 KB |
testcase_16 | AC | 541 ms
8,320 KB |
testcase_17 | AC | 598 ms
9,012 KB |
testcase_18 | AC | 145 ms
7,296 KB |
testcase_19 | AC | 183 ms
8,220 KB |
testcase_20 | AC | 598 ms
9,960 KB |
testcase_21 | AC | 142 ms
7,168 KB |
testcase_22 | AC | 165 ms
8,060 KB |
testcase_23 | AC | 108 ms
6,940 KB |
testcase_24 | AC | 167 ms
7,552 KB |
testcase_25 | AC | 169 ms
8,064 KB |
testcase_26 | AC | 287 ms
6,940 KB |
testcase_27 | AC | 188 ms
8,704 KB |
testcase_28 | AC | 474 ms
8,892 KB |
testcase_29 | AC | 171 ms
7,936 KB |
testcase_30 | AC | 188 ms
8,308 KB |
testcase_31 | AC | 567 ms
8,576 KB |
testcase_32 | AC | 453 ms
7,680 KB |
testcase_33 | WA | - |
testcase_34 | AC | 496 ms
8,316 KB |
testcase_35 | AC | 348 ms
6,944 KB |
testcase_36 | AC | 275 ms
6,940 KB |
testcase_37 | AC | 629 ms
8,900 KB |
testcase_38 | AC | 602 ms
9,108 KB |
testcase_39 | AC | 628 ms
8,960 KB |
testcase_40 | AC | 285 ms
6,944 KB |
testcase_41 | AC | 664 ms
9,700 KB |
testcase_42 | AC | 505 ms
8,304 KB |
testcase_43 | AC | 456 ms
8,388 KB |
testcase_44 | AC | 687 ms
9,764 KB |
testcase_45 | AC | 398 ms
7,424 KB |
testcase_46 | AC | 403 ms
7,040 KB |
testcase_47 | AC | 598 ms
9,188 KB |
testcase_48 | AC | 450 ms
7,552 KB |
testcase_49 | AC | 406 ms
6,944 KB |
testcase_50 | AC | 300 ms
6,944 KB |
testcase_51 | AC | 326 ms
6,940 KB |
testcase_52 | AC | 209 ms
6,940 KB |
testcase_53 | AC | 568 ms
8,576 KB |
testcase_54 | AC | 417 ms
7,396 KB |
testcase_55 | AC | 460 ms
7,936 KB |
testcase_56 | AC | 477 ms
7,808 KB |
testcase_57 | AC | 431 ms
7,552 KB |
testcase_58 | AC | 160 ms
6,940 KB |
testcase_59 | WA | - |
testcase_60 | AC | 390 ms
7,900 KB |
testcase_61 | AC | 337 ms
6,940 KB |
testcase_62 | AC | 537 ms
8,668 KB |
testcase_63 | AC | 580 ms
9,316 KB |
testcase_64 | AC | 748 ms
10,388 KB |
testcase_65 | AC | 340 ms
6,944 KB |
testcase_66 | AC | 604 ms
8,988 KB |
testcase_67 | AC | 247 ms
6,940 KB |
testcase_68 | AC | 296 ms
6,944 KB |
testcase_69 | AC | 193 ms
6,940 KB |
testcase_70 | AC | 247 ms
6,940 KB |
testcase_71 | AC | 355 ms
6,940 KB |
testcase_72 | AC | 527 ms
8,320 KB |
testcase_73 | AC | 429 ms
7,552 KB |
testcase_74 | AC | 589 ms
8,580 KB |
testcase_75 | AC | 581 ms
8,960 KB |
testcase_76 | AC | 521 ms
8,064 KB |
testcase_77 | AC | 526 ms
8,448 KB |
testcase_78 | AC | 682 ms
9,736 KB |
testcase_79 | AC | 523 ms
8,704 KB |
testcase_80 | AC | 601 ms
9,700 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; /* #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, 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); } // // 積が 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 T = __int128_t; using Rat = RationalNum<T>; VAR(ll, q); // VAR(ll, xa, ya, xb, yb, xc, yc); 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); // パターンとして,次の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; // 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; // 半径 const Rat dx = cx - X[0]; const Rat dy = cy - Y[0]; 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) { Rat d2 = (x[i] - cx).pow(2) + (y[i] - cy).pow(2); Yn(d2 <= r2); } } // entry point int main() { solve(); return 0; }