답안 #430201

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
430201 2021-06-16T12:02:12 Z palilo 공룡 발자국 (KOI18_footprint) C++17
100 / 100
91 ms 460 KB
#include <bits/stdc++.h>
using namespace std;

/* basics */
namespace geo {
#define EPS 1e-8
template <typename T, enable_if_t<is_integral<T>::value, bool> = true>
int sign(T x) { return (x > 0) - (x < 0); }
template <typename T, enable_if_t<is_floating_point<T>::value, bool> = true>
int sign(T x) { return (x > EPS) - (x < -EPS); }
}; // namespace geo

/* point2D */
namespace geo {
template <typename T>
struct point2D {
    T x, y;
    point2D() = default;
    point2D(T _x, T _y) : x(_x), y(_y) {}
    template <typename U>
    explicit point2D(const point2D<U>& p) : x(p.x), y(p.y) {}

    using P = point2D;

    bool operator<(const P& p) const { return tie(x, y) < tie(p.x, p.y); }
    bool operator==(const P& p) const { return tie(x, y) == tie(p.x, p.y); }
    bool operator!=(const P& p) const { return tie(x, y) != tie(p.x, p.y); }

    friend P operator+(const P& a, const P& b) { return P(a.x + b.x, a.y + b.y); }
    friend P operator-(const P& a, const P& b) { return P(a.x - b.x, a.y - b.y); }
    friend P operator*(const P& a, const T& scalar) { return P(a.x * scalar, a.y * scalar); }
    friend P operator*(const T& scalar, const P& a) { return P(scalar * a.x, scalar * a.y); }
    friend P operator/(const P& a, const T& scalar) { return P(a.x / scalar, a.y / scalar); }

    friend ostream& operator<<(ostream& o, const P& p) { return o << '(' << p.x << ", " << p.y << ')'; }
    friend istream& operator>>(istream& i, P& p) { return i >> p.x >> p.y; }

    T dot(const P& p) const { return x * p.x + y * p.y; }
    T cross(const P& p) const { return x * p.y - y * p.x; }
    T cross(const P& a, const P& b) const { return (a - *this).cross(b - *this); }

    T dist2() const { return x * x + y * y; }
    double dist() const { return sqrt(dist2()); }

    P perp_cw() const { return P(y, -x); }
    P perp_ccw() const { return P(-y, x); }

    P unit() const { return *this / dist(); }
    P normal() const { return perp_ccw().unit(); }

    P unit_int() const { return x || y ? *this / gcd(x, y) : *this; }
    P normal_int() const { return perp_ccw().unit_int(); }

    bool same_dir(const P& p) const { return cross(p) == 0 && dot(p) > 0; }
    int side_of(const P& s, const P& e) const {
        if constexpr (is_integral_v<T>) {
            return sign(s.cross(e, *this));
        } else {
            auto res = (e - s).cross(*this - s);
            double l = (e - s).dist() * EPS;
            return (res > l) - (res < -l);
        }
    }

    double angle() const { return atan2(y, x); }
    P rotate(double radian) const {
        return P(x * cos(radian) - y * sin(radian), x * sin(radian) + y * cos(radian));
    }
};
}; // namespace geo

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
#ifdef palilo
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    using point = geo::point2D<int64_t>;

    int n;
    cin >> n;

    vector<point> a(n);
    for (auto& p : a) cin >> p;

    swap(a.back(), *min_element(a.begin(), a.end(), [&](const auto& lhs, const auto& rhs) {
        return lhs.y < rhs.y;
    }));
    sort(a.begin(), a.end() - 1, [&](const auto& lhs, const auto& rhs) {
        return a.back().cross(lhs, rhs) < 0;
    });

    // {#, prev id}
    vector gol(n, -1), garak(n, 1);
    vector gol_prev(n, n - 1), garak_prev(n, n - 1);

    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            if (i != n - 1 && a.back().cross(a[j], a[i]) == 0) break;
            if (a[i].side_of(a[garak_prev[j]], a[j]) == -1) {
                if (gol[i] < garak[j] + 1 || (gol[i] == garak[j] + 1 && a[j].side_of(a[gol_prev[i]], a[i]) == 1))
                    gol[i] = garak[j] + 1, gol_prev[i] = j;
            }
            if (a[i].side_of(a[gol_prev[j]], a[j]) == 1) {
                if (garak[i] < gol[j] + 1 || (garak[i] == gol[j] + 1 && a[j].side_of(a[garak_prev[i]], a[i]) == -1))
                    garak[i] = gol[j] + 1, garak_prev[i] = j;
            }
        }
    }

    if (gol.back() < 4) return cout << 0, 0;

    vector<int> ans;
    ans.reserve(gol.back());

    for (int flag = 1, i = n - 1, cnt = gol.back(); cnt--; flag ^= 1) {
        ans.emplace_back(i);
        i = (flag ? gol_prev : garak_prev)[i];
    }

    cout << ans.size() << '\n';
    for (const auto& id : ans)
        cout << a[id].x << ' ' << a[id].y << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 440 KB Output is correct
2 Correct 68 ms 436 KB Output is correct
3 Correct 73 ms 452 KB Output is correct
4 Correct 58 ms 428 KB Output is correct
5 Correct 54 ms 432 KB Output is correct
6 Correct 56 ms 432 KB Output is correct
7 Correct 56 ms 452 KB Output is correct
8 Correct 57 ms 436 KB Output is correct
9 Correct 54 ms 428 KB Output is correct
10 Correct 55 ms 448 KB Output is correct
11 Correct 56 ms 412 KB Output is correct
12 Correct 64 ms 452 KB Output is correct
13 Correct 71 ms 448 KB Output is correct
14 Correct 71 ms 448 KB Output is correct
15 Correct 68 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 328 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 3 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 320 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 440 KB Output is correct
2 Correct 68 ms 436 KB Output is correct
3 Correct 73 ms 452 KB Output is correct
4 Correct 58 ms 428 KB Output is correct
5 Correct 54 ms 432 KB Output is correct
6 Correct 56 ms 432 KB Output is correct
7 Correct 56 ms 452 KB Output is correct
8 Correct 57 ms 436 KB Output is correct
9 Correct 54 ms 428 KB Output is correct
10 Correct 55 ms 448 KB Output is correct
11 Correct 56 ms 412 KB Output is correct
12 Correct 64 ms 452 KB Output is correct
13 Correct 71 ms 448 KB Output is correct
14 Correct 71 ms 448 KB Output is correct
15 Correct 68 ms 448 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 2 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 2 ms 328 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 3 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 2 ms 332 KB Output is correct
47 Correct 2 ms 320 KB Output is correct
48 Correct 2 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 2 ms 204 KB Output is correct
51 Correct 59 ms 448 KB Output is correct
52 Correct 73 ms 452 KB Output is correct
53 Correct 55 ms 448 KB Output is correct
54 Correct 80 ms 436 KB Output is correct
55 Correct 65 ms 460 KB Output is correct
56 Correct 75 ms 460 KB Output is correct
57 Correct 74 ms 436 KB Output is correct
58 Correct 74 ms 452 KB Output is correct
59 Correct 76 ms 448 KB Output is correct
60 Correct 69 ms 456 KB Output is correct
61 Correct 91 ms 452 KB Output is correct
62 Correct 88 ms 440 KB Output is correct
63 Correct 73 ms 460 KB Output is correct
64 Correct 60 ms 460 KB Output is correct
65 Correct 62 ms 460 KB Output is correct
66 Correct 57 ms 332 KB Output is correct
67 Correct 61 ms 332 KB Output is correct
68 Correct 60 ms 324 KB Output is correct