結果

問題 No.2173 Nightcord
ユーザー KudeKude
提出日時 2022-12-25 10:28:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,358 ms / 2,525 ms
コード長 7,073 bytes
コンパイル時間 3,212 ms
コンパイル使用メモリ 252,996 KB
実行使用メモリ 108,664 KB
最終ジャッジ日時 2023-08-11 02:19:10
合計ジャッジ時間 57,189 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1,803 ms
80,120 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 1,297 ms
58,496 KB
testcase_10 AC 646 ms
32,672 KB
testcase_11 AC 53 ms
5,724 KB
testcase_12 AC 1,051 ms
53,560 KB
testcase_13 AC 89 ms
7,664 KB
testcase_14 AC 2,205 ms
108,540 KB
testcase_15 AC 2,089 ms
108,664 KB
testcase_16 AC 2,318 ms
108,168 KB
testcase_17 AC 196 ms
13,080 KB
testcase_18 AC 724 ms
37,524 KB
testcase_19 AC 8 ms
4,376 KB
testcase_20 AC 691 ms
36,548 KB
testcase_21 AC 985 ms
50,164 KB
testcase_22 AC 1,131 ms
55,396 KB
testcase_23 AC 1,130 ms
52,124 KB
testcase_24 AC 2,271 ms
101,764 KB
testcase_25 AC 1,429 ms
68,188 KB
testcase_26 AC 1,757 ms
85,088 KB
testcase_27 AC 13 ms
4,380 KB
testcase_28 AC 1,617 ms
76,652 KB
testcase_29 AC 246 ms
15,064 KB
testcase_30 AC 2,358 ms
107,352 KB
testcase_31 AC 379 ms
22,248 KB
testcase_32 AC 1,299 ms
66,116 KB
testcase_33 AC 1,936 ms
92,000 KB
testcase_34 AC 2,103 ms
99,388 KB
testcase_35 AC 1,026 ms
50,580 KB
testcase_36 AC 1,173 ms
59,900 KB
testcase_37 AC 1,825 ms
87,244 KB
testcase_38 AC 2,130 ms
97,152 KB
testcase_39 AC 1,928 ms
90,764 KB
testcase_40 AC 2,070 ms
97,152 KB
testcase_41 AC 1,277 ms
61,892 KB
testcase_42 AC 2,073 ms
102,136 KB
testcase_43 AC 108 ms
8,792 KB
testcase_44 AC 5 ms
4,380 KB
testcase_45 AC 353 ms
20,732 KB
testcase_46 AC 1,981 ms
101,176 KB
testcase_47 AC 520 ms
27,708 KB
testcase_48 AC 534 ms
31,244 KB
testcase_49 AC 11 ms
4,384 KB
testcase_50 AC 179 ms
12,188 KB
testcase_51 AC 559 ms
29,944 KB
testcase_52 AC 6 ms
4,380 KB
testcase_53 AC 587 ms
31,928 KB
testcase_54 AC 864 ms
44,464 KB
testcase_55 AC 175 ms
11,964 KB
testcase_56 AC 375 ms
21,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

struct Vec {
  using etype = int;  // type of elements
  using ptype = long long;  // type of product results
  etype x = 0, y = 0;
  constexpr Vec operator-() const { return {-x, -y}; }
  friend constexpr Vec operator+(const Vec& a, const Vec& b) { return {a.x + b.x, a.y + b.y}; }
  friend constexpr Vec operator-(const Vec& a, const Vec& b) { return {a.x - b.x, a.y - b.y}; }
  friend constexpr ptype operator*(const Vec& a, const Vec& b) { return (ptype)a.x * b.y - (ptype)a.y * b.x; }
  template <class T, enable_if_t<is_integral_v<T>>* = nullptr>
  friend constexpr Vec operator*(T c, const Vec& a) { return {c * a.x, c * a.y}; }
  template <class T, enable_if_t<is_integral_v<T>>* = nullptr>
  friend constexpr Vec operator*(const Vec& a, T c) { return c * a; }
  template <class T, enable_if_t<is_integral_v<T>>* = nullptr>
  friend constexpr Vec operator/(const Vec& a, T c) { return {a.x / c, a.y / c}; }
  Vec& operator+=(const Vec& a) { x += a.x; y += a.y; return *this; }
  Vec& operator-=(const Vec& a) { x -= a.x; y -= a.y; return *this; }
  template <class T, enable_if_t<is_integral_v<T>>* = nullptr>
  Vec& operator*=(T c) { x *= c; y *= c; return *this; }
  friend constexpr bool operator==(const Vec& a, const Vec& b) { return a.x == b.x && a.y == b.y; }
  friend constexpr bool operator!=(const Vec& a, const Vec& b) { return !(a == b); }
  constexpr int quadrant() const { return y > 0 ? (x > 0 ? 0 : 1) : y < 0 ? (x < 0 ? 2 : 3) : (x > 0 ? 0 : x < 0 ? 2 : -1); }
  friend constexpr bool operator<(const Vec& a, const Vec& b) {
    int qa = a.quadrant(), qb = b.quadrant();
    if (qa != qb) return qa < qb;
    ptype p1 = (ptype)a.x * b.y, p2 = (ptype)a.y * b.x;
    return p1 > p2 || (p1 == p2 && (a.x != 0 ? abs(a.x) < abs(b.x) : abs(a.y) < abs(b.y)));
  }
  friend constexpr bool operator>(const Vec& a, const Vec& b) { return b < a; }
  friend constexpr bool operator<=(const Vec& a, const Vec& b) { return !(b < a); }
  friend constexpr bool operator>=(const Vec& a, const Vec& b) { return !(a < b); }
  constexpr int ccw(const Vec& u, const Vec& v) const { ptype p = (u - *this) * (v - *this); return p > 0 ? 1 : p < 0 ? -1 : 0; }
  static constexpr bool intersects(const Vec& a, const Vec& b, const Vec& c, const Vec& d) { return a.ccw(b, c) * a.ccw(b, d) <= 0 && c.ccw(d, a) * c.ccw(d, b) <= 0; }
  constexpr bool parallel_to(const Vec& a) const { return (ptype)x * a.y == (ptype)y * a.x; }
  constexpr ptype dot(const Vec& a) const { return (ptype)x * a.x + (ptype)y * a.y; }
  constexpr ptype norm2() const { return (ptype)x * x + (ptype)y * y; }
  constexpr bool is_zero() const { return x == 0 && y == 0; }
  constexpr Vec normalize() const {
    if (y == 0) return Vec{x == 0 ? 0 : 1, 0};
    if (y > 0) return *this;
    return {-x, -y};
    // etype g = gcd(x, y);
    // return *this / (y > 0 ? g : -g);
  }
  constexpr Vec rot90() const { return {-y, x}; }
  // exclusive
  constexpr bool in_between(const Vec& a, const Vec& b) const {
    Vec x = a - *this, y = b - *this;
    return x.parallel_to(y) && x.dot(y) < 0;
  }
  friend std::ostream& operator<< (std::ostream& os, const Vec& t) { return os << t.x << ' ' << t.y; }
  friend std::istream& operator>> (std::istream& os, Vec& t) { return os >> t.x >> t.y; }
};

vector<int> convex_hull(const vector<Vec>& ps) {
  const int n = ps.size();
  if (n <= 1) {
    if (n == 0) return {};
    else return {0};
  }
  vector<int> ord(n);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int i, int j) {
    return ps[i].y < ps[j].y || (ps[i].y == ps[j].y && ps[i].x < ps[j].x);
  });
  vector<int> st1, st2;
  for(int i: ord) {
    int sz = st1.size();
    while(sz >= 2 && (ps[st1[sz - 1]] - ps[st1[sz - 2]]) * (ps[i] - ps[st1[sz - 1]]) <= 0) {
      st1.pop_back();
      sz--;
    }
    st1.push_back(i);
  }
  for(int i: ord) {
    int sz = st2.size();
    while(sz >= 2 && (ps[st2[sz - 1]] - ps[st2[sz - 2]]) * (ps[i] - ps[st2[sz - 1]]) >= 0) {
      st2.pop_back();
      sz--;
    }
    st2.push_back(i);
  }
  assert(st1.front() == st2.front() && st1.back() == st2.back());
  st1.insert(st1.end(), st2.rbegin() + 1, st2.rend() - 1);
  return st1;
}

bool solve() {
  int n, k;
  cin >> n >> k;
  vector<Vec> p1, p2, p(n);
  VI c(n);
  rep(i, n) {
    cin >> p[i] >> c[i];
    (c[i] == 1 ? p1 : p2).emplace_back(p[i]);
  }
  if (p1.empty() || p2.empty()) return false;
  {
    vector<pair<Vec, int>> d; d.reserve(n * (n - 1));
    rep(i, n) rep(j, i) {
      Vec v = (p[i] - p[j]).normalize();
      d.emplace_back(v, i);
      d.emplace_back(v, j);
    }
    assert(int(d.size()) == n * (n - 1));
    sort(all(d));
    int sz = n * (n - 1);
    VI idx;
    for(int l = 0; l < sz;) {
      Vec v = d[l].first;
      int r = l + 1;
      while(r < sz && d[r].first.parallel_to(v)) r++;
      idx.clear();
      for(int i = l; i < r; i++) idx.emplace_back(d[i].second);
      Vec h = v.rot90();
      sort(all(idx), [&](int i, int j) {
        return h.dot(p[j] - p[i]) > 0;
      });
      int idxsz = idx.size();
      for(int li = 0; li < idxsz; li++) {
        int ri = li + 1;
        while(ri < idxsz && h.dot(p[idx[ri]] - p[idx[li]]) == 0) ri++;
        sort(idx.begin() + li, idx.begin() + ri, [&](int i, int j) {
          return v.dot(p[j] - p[i]) > 0;
        });
        int cnt = 0;
        int last = -1;
        for(int i = li; i < ri; i++) if (c[idx[i]] != last) {
          cnt++;
          last = c[idx[i]];
        }
        if (cnt >= 3) return true;
        li = ri;
      }
      l = r;
    }
  }
  if (k >= 4) {
    VI ch1 = convex_hull(p1), ch2 = convex_hull(p2);
    rep(_, 2) {
      if (int sz = ch1.size(); sz >= 2) {
        ch1.emplace_back(ch1[0]);
        for(Vec v: p2) {
          int cnt = 0;
          rep(i, sz) cnt += Vec::intersects(v, Vec{v.x + 1, 1001001001}, p1[ch1[i]], p1[ch1[i + 1]]);
          if (cnt % 2 == 1) return true;
        }
      }
      swap(p1, p2);
      swap(ch1, ch2);
    }
    int sz1 = ch1.size(), sz2 = ch2.size();
    if (sz1 >= 2 && sz2 >= 2) {
      sz1--, sz2--;
      rep(i, sz1) rep(j, sz2) {
        if (Vec::intersects(p1[ch1[i]], p1[ch1[i + 1]], p2[ch2[j]], p2[ch2[j + 1]])) {
          return true;
        }
      }
    }
  }
  return false;
}
  
} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << (solve() ? "Yes\n" : "No\n");
}
0