Submission #1064497

#TimeUsernameProblemLanguageResultExecution timeMemory
1064497Serendipity__공룡 발자국 (KOI18_footprint)C++17
14 / 100
8 ms604 KiB
/*############################################################################################################### ## 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){ if ((l-A[0]).cross(r-A[0]) == 0){ return (l-A[0]).dist2() < (r-A[0]).dist2(); } 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...