結果
問題 | No.2173 Nightcord |
ユーザー | t33f |
提出日時 | 2022-12-25 11:34:14 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,802 bytes |
コンパイル時間 | 1,538 ms |
コンパイル使用メモリ | 96,436 KB |
実行使用メモリ | 13,772 KB |
最終ジャッジ日時 | 2024-11-18 23:06:51 |
合計ジャッジ時間 | 83,709 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
10,624 KB |
testcase_01 | AC | 2 ms
8,576 KB |
testcase_02 | AC | 2 ms
10,624 KB |
testcase_03 | TLE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | WA | - |
testcase_15 | AC | 9 ms
8,576 KB |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | TLE | - |
testcase_35 | TLE | - |
testcase_36 | TLE | - |
testcase_37 | TLE | - |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | TLE | - |
testcase_41 | TLE | - |
testcase_42 | TLE | - |
testcase_43 | AC | 1,794 ms
5,248 KB |
testcase_44 | AC | 8 ms
5,248 KB |
testcase_45 | TLE | - |
testcase_46 | TLE | - |
testcase_47 | TLE | - |
testcase_48 | TLE | - |
testcase_49 | AC | 200 ms
6,816 KB |
testcase_50 | AC | 1,411 ms
6,816 KB |
testcase_51 | TLE | - |
testcase_52 | AC | 103 ms
5,248 KB |
testcase_53 | TLE | - |
testcase_54 | TLE | - |
testcase_55 | TLE | - |
testcase_56 | TLE | - |
ソースコード
#include <numeric> #include <cassert> #include <algorithm> #include <vector> #include <iostream> using namespace std; using P = pair<int, int>; P operator-(const P lhs, const P rhs) { return {lhs.first - rhs.first, lhs.second - rhs.second}; } long long cp(P a, P b) { return (long long)a.first * b.second - (long long)a.second * b.first; } long long dotp(P a, P b) { return (long long)a.first * b.first + (long long)a.second * b.second; } vector<int> convex_hull(const vector<P> &p) { const size_t n = p.size(); vector<int> ps(n); iota(ps.begin(), ps.end(), 0); sort(ps.begin(), ps.end(), [&](int i, int j) { return p[i] < p[j]; }); vector<int> lower; for (int i : ps) { while (lower.size() > 1) { const size_t k = lower.size(); P cur = p[i], prev = p[lower[k-1]], pprev = p[lower[k-2]]; if (cp(prev - pprev, cur - pprev) > 0) break; else lower.pop_back(); } lower.push_back(i); } reverse(ps.begin(), ps.end()); vector<int> upper; for (int i : ps) { while (upper.size() > 1) { const size_t k = upper.size(); P cur = p[i], prev = p[upper[k-1]], pprev = p[upper[k-2]]; if (cp(prev - pprev, cur - pprev) > 0) break; else upper.pop_back(); } upper.push_back(i); } lower.insert(lower.end(), upper.begin()+1, upper.end()); return lower; } ostream &operator<<(ostream &out, P p) { out << p.first << ' ' << p.second; return out; } bool contained_in(P c, const vector<int> &ch, const vector<P> &vs) { assert(ch.size() == vs.size() + 1); for (int i = 0; i < vs.size(); ++i) { const P p = vs[ch[i]], q = vs[ch[i + 1]]; if (cp(p - c, q - c) < 0) return false; } return true; } bool check1(const vector<int> &ch, const vector<P> &vs, const vector<P> &ps) { for (const auto &c : ps) if (contained_in(c, ch, vs)) return true; return false; } inline bool segments_intersect(P p1, P q1, P p2, P q2) { const auto [x1, y1] = p1; const auto [z1, w1] = q1; const auto [x2, y2] = p2; const auto [z2, w2] = q2; if (max(x1, z1) < min(x2, z2) || max(x2, z2) < min(x1, z1) || max(y1, w1) < min(y2, w2) || max(y2, w2) < min(y1, w1)) return false; const int a1 = w1 - y1, b1 = x1 - z1, c1 = -x1 * w1 + y1 * z1, a2 = w2 - y2, b2 = x2 - z2, c2 = -x2 * w2 + y2 * z2, vp1 = a2 * x1 + b2 * y1 + c2, vq1 = a2 * z1 + b2 * w1 + c2, vp2 = a1 * x2 + b1 * y2 + c1, vq2 = a1 * z2 + b1 * w2 + c1; if (vp1 == 0 || vq1 == 0 || vp2 == 0 || vq2 == 0) return true; return (vp1 > 0) != (vq1 > 0) && (vp2 > 0) != (vq2 > 0); } bool check2(const vector<int> &ch1, const vector<P> &vs1, const vector<int> &ch2, const vector<P> &vs2) { for (int i = 0; i < vs1.size(); ++i) { const P p1 = vs1[ch1[i]], q1 = vs1[ch1[i + 1]]; for (int j = 0; j < vs2.size(); ++j) { const P p2 = vs2[ch2[j]], q2 = vs2[ch2[i + 1]]; if (segments_intersect(p1, q1, p2, q2)) return true; } } return false; } bool check3(const vector<P> &ps1, const vector<P> &ps2) { if (ps2.size() <= 1) return false; auto compare_arg = [](P lhs, P rhs) { const auto [x1, y1] = lhs; const auto [x2, y2] = rhs; const bool u1 = y1 > 0 || (y1 == 0 && x1 >= 0), u2 = y2 > 0 || (y2 == 0 && x2 >= 0); if (u1 != u2) return u1; else return cp(lhs, rhs) > 0; }; for (const P ¢er : ps1) { vector<P> ps; for (int j = 0; j < ps2.size(); ++j) ps.emplace_back(ps2[j] - center); sort(ps.begin(), ps.end(), compare_arg); // cerr << "center = " << center << endl; for (P p : ps) cerr << p << ", "; cerr << endl; int j = 0, m = 1; while (j < ps.size()) { cerr << j << endl; while (j != m && cp(ps[j], ps[m]) > 0) if (++m == ps.size()) m = 0; if (cp(ps[j], ps[m]) == 0 && dotp(ps[j], ps[m]) < 0) { // cerr << center << ' ' << ps[j] << ' ' << ps[m] << endl; return true; } ++j; } } return false; } int main() { int n, k; cin >> n >> k; vector<int> x(n), y(n), c(n); for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> c[i]; vector<P> rp, bp; for (int i = 0; i < n; ++i) if (c[i] == 1) rp.emplace_back(x[i], y[i]); else bp.emplace_back(x[i], y[i]); const vector<int> rch = convex_hull(rp), bch = convex_hull(bp); if (k > 3) cout << (check1(rch, rp, bp) || check1(bch, bp, rp) || check2(bch, bp, rch, rp) ? "Yes\n": "No\n"); else cout << (check3(rp, bp) || check3(bp, rp) ? "Yes\n": "No\n"); }