結果
問題 | No.2173 Nightcord |
ユーザー | PCTprobability |
提出日時 | 2022-12-25 00:59:40 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,767 ms / 2,525 ms |
コード長 | 18,722 bytes |
コンパイル時間 | 8,542 ms |
コンパイル使用メモリ | 321,092 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-04-29 09:48:16 |
合計ジャッジ時間 | 44,162 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 1,288 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 4 ms
5,376 KB |
testcase_09 | AC | 915 ms
5,376 KB |
testcase_10 | AC | 486 ms
5,376 KB |
testcase_11 | AC | 40 ms
5,376 KB |
testcase_12 | AC | 838 ms
5,376 KB |
testcase_13 | AC | 74 ms
5,376 KB |
testcase_14 | AC | 1,319 ms
5,376 KB |
testcase_15 | AC | 1,322 ms
5,376 KB |
testcase_16 | AC | 5 ms
5,376 KB |
testcase_17 | AC | 159 ms
5,376 KB |
testcase_18 | AC | 569 ms
5,376 KB |
testcase_19 | AC | 8 ms
5,376 KB |
testcase_20 | AC | 550 ms
5,376 KB |
testcase_21 | AC | 768 ms
5,376 KB |
testcase_22 | AC | 860 ms
5,376 KB |
testcase_23 | AC | 819 ms
5,376 KB |
testcase_24 | AC | 1,661 ms
5,376 KB |
testcase_25 | AC | 1,090 ms
5,376 KB |
testcase_26 | AC | 1,360 ms
5,376 KB |
testcase_27 | AC | 12 ms
5,376 KB |
testcase_28 | AC | 1,234 ms
5,376 KB |
testcase_29 | AC | 191 ms
5,376 KB |
testcase_30 | AC | 1,767 ms
5,376 KB |
testcase_31 | AC | 307 ms
5,376 KB |
testcase_32 | AC | 905 ms
5,376 KB |
testcase_33 | AC | 1,298 ms
5,376 KB |
testcase_34 | AC | 1,404 ms
5,376 KB |
testcase_35 | AC | 684 ms
5,376 KB |
testcase_36 | AC | 825 ms
5,376 KB |
testcase_37 | AC | 1,224 ms
5,376 KB |
testcase_38 | AC | 1,375 ms
5,376 KB |
testcase_39 | AC | 1,273 ms
5,376 KB |
testcase_40 | AC | 1,375 ms
5,376 KB |
testcase_41 | AC | 846 ms
5,376 KB |
testcase_42 | AC | 1,670 ms
5,376 KB |
testcase_43 | AC | 93 ms
5,376 KB |
testcase_44 | AC | 6 ms
5,376 KB |
testcase_45 | AC | 288 ms
5,376 KB |
testcase_46 | AC | 1,652 ms
5,376 KB |
testcase_47 | AC | 406 ms
5,376 KB |
testcase_48 | AC | 463 ms
5,376 KB |
testcase_49 | AC | 12 ms
5,376 KB |
testcase_50 | AC | 166 ms
5,376 KB |
testcase_51 | AC | 443 ms
5,376 KB |
testcase_52 | AC | 7 ms
5,376 KB |
testcase_53 | AC | 477 ms
5,376 KB |
testcase_54 | AC | 689 ms
5,376 KB |
testcase_55 | AC | 148 ms
5,376 KB |
testcase_56 | AC | 295 ms
5,376 KB |
コンパイルメッセージ
main.cpp: In function 'std::ostream& operator<<(std::ostream&, Point&)': main.cpp:118:1: warning: no return statement in function returning non-void [-Wreturn-type] 118 | } | ^
ソースコード
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using ll = long long; using ld = long double; using ull = unsigned long long; #define endl "\n" typedef pair<int, int> Pii; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i)) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(x) begin(x), end(x) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(s) (s).begin(),(s).end() #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) #define rever(vec) reverse(vec.begin(), vec.end()) #define sor(vec) sort(vec.begin(), vec.end()) #define fi first #define se second #define pb push_back #define P pair<ll,ll> #define PQminll priority_queue<ll, vector<ll>, greater<ll>> #define PQmaxll priority_queue<ll,vector<ll>,less<ll>> #define PQminP priority_queue<P, vector<P>, greater<P>> #define PQmaxP priority_queue<P,vector<P>,less<P>> #define NP next_permutation //const ll mod = 1000000009; const ll mod = 998244353; //const ll mod = 1000000007; const ll inf = 4100000000000000000ll; const ld eps = ld(0.00000000001); static const long double pi = 3.141592653589793; template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];} template<class T,class K>void vcin(vector<T> &n,vector<K> &m){for(int i=0;i<int(n.size());i++) cin>>n[i]>>m[i];} template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;} template<class T>void vcin(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cin>>n[i][j];}}} template<class T>void vcout(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cout<<n[i][j]<<" ";}cout<<endl;}cout<<endl;} void yes(bool a){cout<<(a?"yes":"no")<<endl;} void YES(bool a){cout<<(a?"YES":"NO")<<endl;} void Yes(bool a){cout<<(a?"Yes":"No")<<endl;} void possible(bool a){ cout<<(a?"possible":"impossible")<<endl; } void Possible(bool a){ cout<<(a?"Possible":"Impossible")<<endl; } void POSSIBLE(bool a){ cout<<(a?"POSSIBLE":"IMPOSSIBLE")<<endl; } template<class T>auto min(const T& a){ return *min_element(all(a)); } template<class T>auto max(const T& a){ return *max_element(all(a)); } template<class T,class F>void print(pair<T,F> a){cout<<a.fi<<" "<<a.se<<endl;} template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0;} template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0;} template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}} template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}} ll fastgcd(ll u,ll v){ll shl=0;while(u&&v&&u!=v){bool eu=!(u&1);bool ev=!(v&1);if(eu&&ev){++shl;u>>=1;v>>=1;}else if(eu&&!ev){u>>=1;}else if(!eu&&ev){v>>=1;}else if(u>=v){u=(u-v)>>1;}else{ll tmp=u;u=(v-u)>>1;v=tmp;}}return !u?v<<shl:u<<shl;} ll modPow(ll a, ll n, ll mod) { if(mod==1) return 0;ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; } vector<ll> divisor(ll x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / ans[i]);}}}sor(ans); return ans; } ll pop(ll x){return __builtin_popcountll(x);} ll poplong(ll x){ll y=-1;while(x){x/=2;y++;}return y;} P hyou(P a){ll x=fastgcd(abs(a.fi),abs(a.se));a.fi/=x;a.se/=x;if(a.se<0){a.fi*=-1;a.se*=-1;}return a;} P Pplus(P a,P b){ return hyou({a.fi*b.se+b.fi*a.se,a.se*b.se});} P Ptimes(P a,ll b){ return hyou({a.fi*b,a.se});} P Ptimes(P a,P b){ return hyou({a.fi*b.fi,a.se*b.se});} P Pminus(P a,P b){ return hyou({a.fi*b.se-b.fi*a.se,a.se*b.se});} P Pgyaku(P a){ return hyou({a.se,a.fi});} template<class T> struct Sum{ vector<T> data; Sum(const vector<T>& v):data(v.size()+1){ for(ll i=0;i<v.size();i++) data[i+1]=data[i]+v[i]; } T get(ll l,ll r) const { return data[r]-data[l]; } }; template<class T> struct Sum2{ vector<vector<T>> data; Sum2(const vector<vector<T>> &v):data(v.size()+1,vector<T>(v[0].size()+1)){ for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]=data[i][j+1]+v[i][j]; for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]+=data[i+1][j]; } T get(ll x1,ll y1,ll x2,ll y2) const { return data[x2][y2]+data[x1][y1]-data[x1][y2]-data[x2][y1]; } }; void cincout(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); cout<< fixed << setprecision(15); } using Real = double; using Point = complex< Real >; const Real EPS = 1e-8, PI = acos(-1); inline bool eq(Real a, Real b) { return fabs(b - a) < EPS; } Point operator*(const Point &p, const Real &d) { return Point(real(p) * d, imag(p) * d); } istream &operator>>(istream &is, Point &p) { Real a, b; is >> a >> b; p = Point(a, b); return is; } ostream &operator<<(ostream &os, Point &p) { os << fixed << setprecision(10) << p.real() << " " << p.imag(); } Point rotate(Real theta, const Point &p) { return Point(cos(theta) * p.real() - sin(theta) * p.imag(), sin(theta) * p.real() + cos(theta) * p.imag()); } Real radian_to_degree(Real r) { return (r * 180.0 / PI); } Real degree_to_radian(Real d) { return (d * PI / 180.0); } Real get_angle(const Point &a, const Point &b, const Point &c) { const Point v(b - a), w(c - b); Real alpha = atan2(v.imag(), v.real()), beta = atan2(w.imag(), w.real()); if(alpha > beta) swap(alpha, beta); Real theta = (beta - alpha); return min(theta, 2 * acos(-1) - theta); } namespace std { bool operator<(const Point &a, const Point &b) { return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag(); } } struct Line { Point a, b; Line() = default; Line(Point a, Point b) : a(a), b(b) {} Line(Real A, Real B, Real C) // Ax + By = C { if(eq(A, 0)) a = Point(0, C / B), b = Point(1, C / B); else if(eq(B, 0)) b = Point(C / A, 0), b = Point(C / A, 1); else a = Point(0, C / B), b = Point(C / A, 0); } friend ostream &operator<<(ostream &os, Line &p) { return os << p.a << " to " << p.b; } friend istream &operator>>(istream &is, Line &a) { return is >> a.a >> a.b; } }; struct Segment : Line { Segment() = default; Segment(Point a, Point b) : Line(a, b) {} }; struct Circle { Point p; Real r; Circle() = default; Circle(Point p, Real r) : p(p), r(r) {} }; using Points = vector< Point >; using Polygon = vector< Point >; using Segments = vector< Segment >; using Lines = vector< Line >; using Circles = vector< Circle >; Real cross(const Point &a, const Point &b) { return real(a) * imag(b) - imag(a) * real(b); } Real dot(const Point &a, const Point &b) { return real(a) * real(b) + imag(a) * imag(b); } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C int ccw(const Point &a, Point b, Point c) { b = b - a, c = c - a; if(cross(b, c) > EPS) return +1; // "COUNTER_CLOCKWISE" if(cross(b, c) < -EPS) return -1; // "CLOCKWISE" if(dot(b, c) < 0) return +2; // "ONLINE_BACK" if(norm(b) < norm(c)) return -2; // "ONLINE_FRONT" return 0; // "ON_SEGMENT" } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A bool parallel(const Line &a, const Line &b) { return eq(cross(a.b - a.a, b.b - b.a), 0.0); } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A bool orthogonal(const Line &a, const Line &b) { return eq(dot(a.a - a.b, b.a - b.b), 0.0); } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A Point projection(const Line &l, const Point &p) { double t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b); return l.a + (l.a - l.b) * t; } Point projection(const Segment &l, const Point &p) { double t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b); return l.a + (l.a - l.b) * t; } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_B Point reflection(const Line &l, const Point &p) { return p + (projection(l, p) - p) * 2.0; } bool intersect(const Line &l, const Point &p) { return abs(ccw(l.a, l.b, p)) != 1; } bool intersect(const Line &l, const Line &m) { return abs(cross(l.b - l.a, m.b - m.a)) > EPS || abs(cross(l.b - l.a, m.b - l.a)) < EPS; } bool intersect(const Segment &s, const Point &p) { return ccw(s.a, s.b, p) == 0; } bool intersect(const Line &l, const Segment &s) { return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS; } Real distance(const Line &l, const Point &p); bool intersect(const Circle &c, const Line &l) { return distance(l, c.p) <= c.r + EPS; } bool intersect(const Circle &c, const Point &p) { return abs(abs(p - c.p) - c.r) < EPS; } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_B bool intersect(const Segment &s, const Segment &t) { return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0; } int intersect(const Circle &c, const Segment &l) { if(norm(projection(l, c.p) - c.p) - c.r * c.r > EPS) return 0; auto d1 = abs(c.p - l.a), d2 = abs(c.p - l.b); if(d1 < c.r + EPS && d2 < c.r + EPS) return 0; if(d1 < c.r - EPS && d2 > c.r + EPS || d1 > c.r + EPS && d2 < c.r - EPS) return 1; const Point h = projection(l, c.p); if(dot(l.a - h, l.b - h) < 0) return 2; return 0; } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_A&lang=jp int intersect(Circle c1, Circle c2) { if(c1.r < c2.r) swap(c1, c2); Real d = abs(c1.p - c2.p); if(c1.r + c2.r < d) return 4; if(eq(c1.r + c2.r, d)) return 3; if(c1.r - c2.r < d) return 2; if(eq(c1.r - c2.r, d)) return 1; return 0; } Real distance(const Point &a, const Point &b) { return abs(a - b); } Real distance(const Line &l, const Point &p) { return abs(p - projection(l, p)); } Real distance(const Line &l, const Line &m) { return intersect(l, m) ? 0 : distance(l, m.a); } Real distance(const Segment &s, const Point &p) { Point r = projection(s, p); if(intersect(s, r)) return abs(r - p); return min(abs(s.a - p), abs(s.b - p)); } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_D Real distance(const Segment &a, const Segment &b) { if(intersect(a, b)) return 0; return min({distance(a, b.a), distance(a, b.b), distance(b, a.a), distance(b, a.b)}); } Real distance(const Line &l, const Segment &s) { if(intersect(l, s)) return 0; return min(distance(l, s.a), distance(l, s.b)); } Point crosspoint(const Line &l, const Line &m) { Real A = cross(l.b - l.a, m.b - m.a); Real B = cross(l.b - l.a, l.b - m.a); if(eq(abs(A), 0.0) && eq(abs(B), 0.0)) return m.a; return m.a + (m.b - m.a) * B / A; } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_C Point crosspoint(const Segment &l, const Segment &m) { return crosspoint(Line(l), Line(m)); } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_D pair< Point, Point > crosspoint(const Circle &c, const Line l) { Point pr = projection(l, c.p); Point e = (l.b - l.a) / abs(l.b - l.a); if(eq(distance(l, c.p), c.r)) return {pr, pr}; double base = sqrt(c.r * c.r - norm(pr - c.p)); return {pr - e * base, pr + e * base}; } pair< Point, Point > crosspoint(const Circle &c, const Segment &l) { Line aa = Line(l.a, l.b); if(intersect(c, l) == 2) return crosspoint(c, aa); auto ret = crosspoint(c, aa); if(dot(l.a - ret.first, l.b - ret.first) < 0) ret.second = ret.first; else ret.first = ret.second; return ret; } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_E pair< Point, Point > crosspoint(const Circle &c1, const Circle &c2) { Real d = abs(c1.p - c2.p); Real a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d)); Real t = atan2(c2.p.imag() - c1.p.imag(), c2.p.real() - c1.p.real()); Point p1 = c1.p + Point(cos(t + a) * c1.r, sin(t + a) * c1.r); Point p2 = c1.p + Point(cos(t - a) * c1.r, sin(t - a) * c1.r); return {p1, p2}; } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_F pair< Point, Point > tangent(const Circle &c1, const Point &p2) { return crosspoint(c1, Circle(p2, sqrt(norm(c1.p - p2) - c1.r * c1.r))); } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_G Lines tangent(Circle c1, Circle c2) { Lines ret; if(c1.r < c2.r) swap(c1, c2); Real g = norm(c1.p - c2.p); if(eq(g, 0)) return ret; Point u = (c2.p - c1.p) / sqrt(g); Point v = rotate(PI * 0.5, u); for(int s : {-1, 1}) { Real h = (c1.r + s * c2.r) / sqrt(g); if(eq(1 - h * h, 0)) { ret.emplace_back(c1.p + u * c1.r, c1.p + (u + v) * c1.r); } else if(1 - h * h > 0) { Point uu = u * h, vv = v * sqrt(1 - h * h); ret.emplace_back(c1.p + (uu + vv) * c1.r, c2.p - (uu + vv) * c2.r * s); ret.emplace_back(c1.p + (uu - vv) * c1.r, c2.p - (uu - vv) * c2.r * s); } } return ret; } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_B bool is_convex(const Polygon &p) { int n = (int) p.size(); for(int i = 0; i < n; i++) { if(ccw(p[(i + n - 1) % n], p[i], p[(i + 1) % n]) == -1) return false; } return true; } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_A Polygon convex_hull(Polygon &p) { int n = (int) p.size(), k = 0; if(n <= 2) return p; sort(p.begin(), p.end()); vector< Point > ch(2 * n); for(int i = 0; i < n; ch[k++] = p[i++]) { while(k >= 2 && cross(ch[k - 1] - ch[k - 2], p[i] - ch[k - 1]) < 0) --k; } for(int i = n - 2, t = k + 1; i >= 0; ch[k++] = p[i--]) { while(k >= t && cross(ch[k - 1] - ch[k - 2], p[i] - ch[k - 1]) < 0) --k; } ch.resize(k - 1); return ch; } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_C enum { OUT, ON, IN }; int contains(const Polygon &Q, const Point &p) { bool in = false; for(int i = 0; i < Q.size(); i++) { Point a = Q[i] - p, b = Q[(i + 1) % Q.size()] - p; if(a.imag() > b.imag()) swap(a, b); if(a.imag() <= 0 && 0 < b.imag() && cross(a, b) < 0) in = !in; if(cross(a, b) == 0 && dot(a, b) <= 0) return ON; } return in ? IN : OUT; } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1033 void merge_segments(vector< Segment > &segs) { auto merge_if_able = [](Segment &s1, const Segment &s2) { if(abs(cross(s1.b - s1.a, s2.b - s2.a)) > EPS) return false; if(ccw(s1.a, s2.a, s1.b) == 1 || ccw(s1.a, s2.a, s1.b) == -1) return false; if(ccw(s1.a, s1.b, s2.a) == -2 || ccw(s2.a, s2.b, s1.a) == -2) return false; s1 = Segment(min(s1.a, s2.a), max(s1.b, s2.b)); return true; }; for(int i = 0; i < segs.size(); i++) { if(segs[i].b < segs[i].a) swap(segs[i].a, segs[i].b); } for(int i = 0; i < segs.size(); i++) { for(int j = i + 1; j < segs.size(); j++) { if(merge_if_able(segs[i], segs[j])) { segs[j--] = segs.back(), segs.pop_back(); } } } } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1033 vector< vector< int > > segment_arrangement(vector< Segment > &segs, vector< Point > &ps) { vector< vector< int > > g; int N = (int) segs.size(); for(int i = 0; i < N; i++) { ps.emplace_back(segs[i].a); ps.emplace_back(segs[i].b); for(int j = i + 1; j < N; j++) { const Point p1 = segs[i].b - segs[i].a; const Point p2 = segs[j].b - segs[j].a; if(cross(p1, p2) == 0) continue; if(intersect(segs[i], segs[j])) { ps.emplace_back(crosspoint(segs[i], segs[j])); } } } sort(begin(ps), end(ps)); ps.erase(unique(begin(ps), end(ps)), end(ps)); int M = (int) ps.size(); g.resize(M); for(int i = 0; i < N; i++) { vector< int > vec; for(int j = 0; j < M; j++) { if(intersect(segs[i], ps[j])) { vec.emplace_back(j); } } for(int j = 1; j < vec.size(); j++) { g[vec[j - 1]].push_back(vec[j]); g[vec[j]].push_back(vec[j - 1]); } } return (g); } // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_C Polygon convex_cut(const Polygon &U, Line l) { Polygon ret; for(int i = 0; i < U.size(); i++) { Point now = U[i], nxt = U[(i + 1) % U.size()]; if(ccw(l.a, l.b, now) != -1) ret.push_back(now); if(ccw(l.a, l.b, now) * ccw(l.a, l.b, nxt) < 0) { ret.push_back(crosspoint(Line(now, nxt), l)); } } return (ret); } int main() { cincout(); ll n,k; cin>>n>>k; vector<pair<int,int>> a,b; for(int i=0;i<n;i++){ int x,y,z; cin>>x>>y>>z; if(z==1) a.pb({x,y}); else b.pb({x,y}); } bool ok=false; for(int i=0;i<int(a.size());i++){ map<pair<int,int>,vector<pair<int,int>>> m; for(int j=0;j<int(b.size());j++){ int x=a[i].fi-b[j].fi,y=a[i].se-b[j].se; int z=gcd(x,y); x/=z; y/=z; if(y==0){ x=abs(x); } if(y<0){ y*=-1; x*=-1; } m[{x,y}].pb({(a[i].fi-b[j].fi),(a[i].se-b[j].se)}); } for(auto e:m){ bool p=false,q=false; for(auto f:e.se){ if(f.fi+f.se==0){ if(f.fi<0) p=true; else q=true; } else{ if(f.fi+f.se<0) p=true; else q=true; } } if(p&&q) ok=true; } } swap(a,b); for(int i=0;i<int(a.size());i++){ map<pair<int,int>,vector<pair<int,int>>> m; for(int j=0;j<int(b.size());j++){ int x=a[i].fi-b[j].fi,y=a[i].se-b[j].se; int z=gcd(x,y); x/=z; y/=z; if(y==0){ x=abs(x); } if(y<0){ y*=-1; x*=-1; } m[{x,y}].pb({(a[i].fi-b[j].fi),(a[i].se-b[j].se)}); } for(auto e:m){ bool p=false,q=false; for(auto f:e.se){ if(ll(f.fi)+ll(f.se)==0){ if(f.fi<0) p=true; else q=true; } else{ if(f.fi<f.se) p=true; else q=true; } } if(p&&q) ok=true; } } if(k==3){ Yes(ok); return 0; } Polygon p(int(a.size())); for(int i=0;i<a.size();i++){ Real s,t; s=a[i].fi; t=a[i].se; p[i]={s,t}; } Polygon q(int(b.size())); for(int i=0;i<b.size();i++){ Real s,t; s=b[i].fi; t=b[i].se; q[i]={s,t}; } p=convex_hull(p); q=convex_hull(q); if(p.size()>q.size()) swap(p,q); for(int i=0;i<q.size();i++){ Line l={q[i],q[(i+1)%(int(q.size()))]}; p=convex_cut(p,l); } // for(auto e:p) cout<<real(e)<<" "<<imag(e)<<endl; if(p.size()>0){ cout<<"Yes"<<endl; } else{ Yes(ok); } }