답안 #1064488

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1064488 2024-08-18T13:18:22 Z Serendipity__ 공룡 발자국 (KOI18_footprint) C++17
14 / 100
8 ms 860 KB
/*###############################################################################################################
##                                    Author : Kim Tae Yoon (Serendipity__)                                    ##
###############################################################################################################*/

#include <bits/stdc++.h>
#define fastio std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define prntyes cout<<"Yes\n";
#define prntno cout<<"No\n";
using namespace std;
// mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); // random int64 generator
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef __int128 ll128;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pii;
typedef complex<double> inum;
// Macros from KACTL pdf
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
typedef vector<double> vd;
const double PI = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000000LL;
const ll MAX = 200005; // depending on the problem
const ll MOD = 998244353; // depending on the problem


template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
    typedef Point P;
    T x, y;
    explicit Point(T x=0, T y=0) : x(x), y(y) {}
    bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
    bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
    P operator+(P p) const { return P(x+p.x, y+p.y); }
    P operator-(P p) const { return P(x-p.x, y-p.y); }
    P operator*(T d) const { return P(x*d, y*d); }
    P operator/(T d) const { return P(x/d, y/d); }
    T dot(P p) const { return x*p.x + y*p.y; }
    T cross(P p) const { return x*p.y - y*p.x; }
    T cross(P a, P b) const { return (a-*this).cross(b-*this); }
    T dist2() const { return x*x + y*y; }
    double dist() const { return sqrt((double)dist2()); }
    // angle to x-axis in interval [-pi, pi]
    double angle() const { return atan2(y, x); }
    P unit() const { return *this/dist(); } // makes dist()=1
    P perp() const { return P(-y, x); } // rotates +90 degrees
    P normal() const { return perp().unit(); }
    // returns point rotated 'a' radians ccw around the origin
    P rotate(double a) const {
        return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
    friend ostream& operator<<(ostream& os, P p) {
        return os << "(" << p.x << "," << p.y << ")"; }
};
typedef Point<ll> P;

void solve() {
    ll N; cin>>N;

    vector<P> A(N);
    for (int i=0;i<N;i++){
        ll x,y; cin>>x>>y;
        A[i] = P(x,y);
    }
    int s = 0;
    for (int i=1;i<N;i++){
        if (A[i].y < A[s].y){
            s = i;
        }
    }
    swap(A[0],A[s]);

    sort(A.begin()+1, A.end(), [&](P l, P r){
        return (l-A[0]).cross(r-A[0]) > 0;
    });

    vector<int> dp(N),ne(N,-1),in(N,-1);
    for (int j=N-1;j>=1;j--){
        dp[j] = 1;
        P mn = A[j] - A[0];
        int idx = -1;
        for (int i=j+1;i<N;i++){
            if (mn.cross(A[i]-A[j]) < 0){
                if (dp[j] < dp[i]+1){
                    dp[j] = dp[i]+1;
                    ne[j] = i;
                    in[j] = idx;
                }
            }

            if (mn.cross(A[i]-A[j]) > 0){
                mn = A[i]-A[j];
                idx = i;
            }
        }
    }

    vector<P> res;
    res.push_back(A[0]);

    int u = max_element(dp.begin(), dp.end()) - dp.begin();
    if (dp[u] <= 1){cout<<0; return;}

    cout<<2*dp[u]<<"\n";

    while(1){
        res.push_back(A[u]);
        if (dp[u] == 1){break;}
        res.push_back(A[in[u]]);
        u = ne[u];
    }

    for (auto it:res){
        cout<<it.x<<" "<<it.y<<"\n";
    }

}

int main() {
    fastio;
    int tc = 1;
    // cin >> tc;
    while (tc--) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 604 KB Output is correct
2 Correct 6 ms 604 KB Output is correct
3 Correct 6 ms 604 KB Output is correct
4 Correct 6 ms 604 KB Output is correct
5 Correct 6 ms 604 KB Output is correct
6 Correct 6 ms 604 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 6 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 6 ms 604 KB Output is correct
11 Correct 6 ms 604 KB Output is correct
12 Correct 6 ms 860 KB Output is correct
13 Correct 6 ms 604 KB Output is correct
14 Correct 6 ms 604 KB Output is correct
15 Correct 6 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 604 KB Output is correct
2 Correct 6 ms 604 KB Output is correct
3 Correct 6 ms 604 KB Output is correct
4 Correct 6 ms 604 KB Output is correct
5 Correct 6 ms 604 KB Output is correct
6 Correct 6 ms 604 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 6 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 6 ms 604 KB Output is correct
11 Correct 6 ms 604 KB Output is correct
12 Correct 6 ms 860 KB Output is correct
13 Correct 6 ms 604 KB Output is correct
14 Correct 6 ms 604 KB Output is correct
15 Correct 6 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 456 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Halted 0 ms 0 KB -