Submission details
Task:Broken car race
Sender:Aalto CS-A1140 Team 2
Submission time:2025-11-08 14:33:41 +0200
Language:C++ (C++17)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.00 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#20ACCEPTED0.00 sdetails
#21ACCEPTED0.03 sdetails
#22ACCEPTED0.04 sdetails
#23ACCEPTED0.04 sdetails
#24ACCEPTED0.04 sdetails
#25ACCEPTED0.02 sdetails
#26ACCEPTED0.02 sdetails
#27ACCEPTED0.02 sdetails
#28ACCEPTED0.02 sdetails

Code

#include <bits/stdc++.h>
using namespace std;

#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()

using ll = long long;

struct Angle {
	int x, y;
	int t;
	Angle(int x, int y, int t = 0) : x(x), y(y), t(t) {}
	Angle operator-(Angle b) const { return {x - b.x, y - b.y, t}; }
	int half() const {
		assert(x || y);
		return y < 0 || (y == 0 && x < 0);
	}
};

bool operator<(Angle a, Angle b) {
	return make_tuple(a.t, a.half(), a.y * (ll)b.x) <
		   make_tuple(b.t, b.half(), a.x * (ll)b.y);
}

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); }
};

typedef Point<ll> P;

vector<P> convexHull(vector<P> pts) {
	if (sz(pts) <= 1) return pts;
	sort(all(pts));
	vector<P> h(sz(pts) + 1);
	int s = 0, t = 0;
	for (int it = 2; it--; s = --t, reverse(all(pts)))
		for (P p : pts) {
			while (t >= s + 2 && h[t - 2].cross(h[t - 1], p) <= 0) t--;
			h[t++] = p;
		}
	return {h.begin(), h.begin() + t - (t == 2 && h[0] == h[1])};
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n;
	cin >> n;

	vector<P> p(n);
	for (int i = 0; i < n; ++i) {
		cin >> p[i].x >> p[i].y;
	}

	auto c = convexHull(p);

	if (sz(c) >= 4) {
		cout << "YES" << endl;
		for (int i = 0; i < 4; ++i) {
			cout << c[i].x << " " << c[i].y << endl;
		}
		return 0;
	}


	if (sz(c) < 3) {
		cout << "NO" << endl;
		return 0;
	}


	vector<P> opt;

	for (int i = 0; i < n; ++i) {
		bool f = 0;
		for (auto u : c) if (p[i] == u) f = 1;
		for (auto u : opt) if (p[i] == u) f = 1;
		if (!f) {
			opt.push_back(p[i]);
		}
		if (sz(opt) >= 2) break;
	}

	if (sz(opt) < 2) {
		cout << "NO" << endl;
		return 0;
	}

	auto test = [&](vector<P> t) {
		auto ct = convexHull(t);
		if (sz(ct) == 4) {
			cout << "YES" << endl;
			for (int i = 0; i < 4; ++i) {
				cout << ct[i].x << " " << ct[i].y << endl;
			}
			exit(0);
		}
	};

	for (int i = 0; i < 3; ++i) {
		test({c[i], c[(i + 1) % 3], opt[0], opt[1]});
	}

	assert(false);
}

Test details

Test 1

Verdict: ACCEPTED

input
4
0 0
1 1
0 1
1 0

correct output
YES
0 0
1 0
1 1
0 1

user output
YES
0 0
1 0
1 1
0 1

Test 2

Verdict: ACCEPTED

input
4
0 0
3 0
0 3
1 1

correct output
NO

user output
NO

Test 3

Verdict: ACCEPTED

input
4
-999999999 -1000000000
-1000000000 -999999999
1000000000 1000000000
999999999 999999999

correct output
NO

user output
NO

Test 4

Verdict: ACCEPTED

input
4
-1 -999999999
-1000000000 -1000000000
1 -999999999
1000000000 -999999998

correct output
YES
-1000000000 -1000000000
1 -999999999
1000000000 -999999998
-1 -999999999

user output
YES
-1000000000 -1000000000
1 -999999999
1000000000 -999999998
-1 -999999999

Test 5

Verdict: ACCEPTED

input
4
0 -999999999
-999999999 -1000000000
1 -999999999
1000000000 -999999998

correct output
YES
-999999999 -1000000000
1 -999999999
1000000000 -999999998
0 -999999999

user output
YES
-999999999 -1000000000
1 -999999999
1000000000 -999999998
0 -999999999

Test 6

Verdict: ACCEPTED

input
1
0 0

correct output
NO

user output
NO

Test 7

Verdict: ACCEPTED

input
2
0 0
1 1

correct output
NO

user output
NO

Test 8

Verdict: ACCEPTED

input
3
0 0
1 1
2 1

correct output
NO

user output
NO

Test 9

Verdict: ACCEPTED

input
4
0 0
1 1
2 4
3 4

correct output
YES
0 0
1 1
3 4
2 4

user output
YES
0 0
1 1
3 4
2 4

Test 10

Verdict: ACCEPTED

input
4
3 4
0 0
1 1
2 4

correct output
YES
0 0
1 1
3 4
2 4

user output
YES
0 0
1 1
3 4
2 4

Test 11

Verdict: ACCEPTED

input
4
-947476077 -331979804
-947475987 -331979714
-947475897 -331979444
-947475807 -331979444

correct output
YES
-947476077 -331979804
-947475987 -331979714
-947475807 -331979444
-947475897 -331979444

user output
YES
-947476077 -331979804
-947475987 -331979714
-947475807 -331979444
-947475897 -331979444

Test 12

Verdict: ACCEPTED

input
4
-318972071 -438408913
-318972227 -438409225
-318971993 -438408913
-318972149 -438409147

correct output
YES
-318972227 -438409225
-318972149 -438409147
-318971993 -438408913
-318972071 -438408913

user output
YES
-318972227 -438409225
-318972149 -438409147
-318971993 -438408913
-318972071 -438408913

Test 13

Verdict: ACCEPTED

input
5
0 0
1 1
2 4
3 4
...

correct output
YES
0 0
1 1
3 4
2 4

user output
YES
0 0
4 1
3 4
2 4

Test 14

Verdict: ACCEPTED

input
5
2 4
3 4
4 1
0 0
...

correct output
YES
0 0
1 1
3 4
2 4

user output
YES
0 0
4 1
3 4
2 4

Test 15

Verdict: ACCEPTED

input
5
-298761158 -20751946
-298761080 -20751868
-298761002 -20751634
-298760924 -20751634
...

correct output
YES
-298761158 -20751946
-298761080 -20751868
-298760924 -20751634
-298761002 -20751634

user output
YES
-298761158 -20751946
-298760846 -20751868
-298760924 -20751634
-298761002 -20751634

Test 16

Verdict: ACCEPTED

input
5
-664720312 -463218521
-664720310 -463218527
-664720318 -463218529
-664720316 -463218527
...

correct output
YES
-664720318 -463218529
-664720316 -463218527
-664720312 -463218521
-664720314 -463218521

user output
YES
-664720318 -463218529
-664720310 -463218527
-664720312 -463218521
-664720314 -463218521

Test 17

Verdict: ACCEPTED

input
1000
0 0
1 1
2 4
3 9
...

correct output
YES
0 0
1 1
2 4
3 9

user output
YES
0 0
860 3
964 7
977 15

Test 18

Verdict: ACCEPTED

input
1000
258 979
961 286
526 210
359 738
...

correct output
YES
258 979
359 738
961 286
938 1005

user output
YES
0 0
860 3
964 7
977 15

Test 19

Verdict: ACCEPTED

input
1000
-921893439 -773165050
-921893387 -773164998
-921893335 -773164842
-921893283 -773164582
...

correct output
YES
-921893439 -773165050
-921893387 -773164998
-921893335 -773164842
-921893283 -773164582

user output
YES
-921893439 -773165050
-921848719 -773164894
-921843311 -773164686
-921842635 -773164270

Test 20

Verdict: ACCEPTED

input
1000
-857937339 -260514932
-857900604 -260453645
-857927295 -260433371
-857907672 -260495123
...

correct output
YES
-857970726 -260438486
-857937339 -260514932
-857907672 -260495123
-857927295 -260433371

user output
YES
-857989605 -260517443
-857909625 -260517164
-857899953 -260516792
-857898744 -260516048

Test 21

Verdict: ACCEPTED

input
100000
0 0
1 1
2 4
3 9
...

correct output
YES
0 0
1 1
2 4
3 9

user output
YES
0 0
55522 6
91418 14
99999 16

Test 22

Verdict: ACCEPTED

input
100000
48266 36871
12387 33167
41280 87283
87910 36263
...

correct output
YES
41172 82734
48266 36871
87910 36263
41280 87283

user output
YES
0 0
55522 6
91418 14
99999 16

Test 23

Verdict: ACCEPTED

input
100000
-76010768 -505453376
-76010702 -505453310
-76010636 -505453112
-76010570 -505452782
...

correct output
YES
-76010768 -505453376
-76010702 -505453310
-76010636 -505453112
-76010570 -505452782

user output
YES
-76010768 -505453376
-72346316 -505452980
-69977180 -505452452
-69410834 -505452320

Test 24

Verdict: ACCEPTED

input
100000
-229347383 -980287597
-234601047 -984160539
-228269246 -981952727
-228868065 -980735452
...

correct output
YES
-234601047 -984160539
-229520466 -983763565
-228868065 -980735452
-229347383 -980287597

user output
YES
-234627327 -986321120
-230574221 -986320682
-227953813 -986320098
-227327400 -986319952

Test 25

Verdict: ACCEPTED

input
49935
0 0
1 1
2 4
317 486
...

correct output
YES
0 0
1 1
317 486
2 4

user output
YES
1 1
99999 16
44974 100001
2 4

Test 26

Verdict: ACCEPTED

input
49935
32628 54449
63501 56035
40017 12250
62461 59485
...

correct output
YES
32628 54449
40017 12250
59069 42091
62461 59485

user output
YES
0 0
99999 16
63501 56035
32628 54449

Test 27

Verdict: ACCEPTED

input
49935
-701962979 -481681059
-701962958 -481681038
-701962937 -481680975
-701956322 -481670853
...

correct output
YES
-701962979 -481681059
-701962958 -481681038
-701956322 -481670853
-701962937 -481680975

user output
YES
-701962958 -481681038
-699863000 -481680723
-701018525 -479581038
-701962937 -481680975

Test 28

Verdict: ACCEPTED

input
49935
-534092520 -499622905
-532312144 -496581113
-529779120 -499152565
-532498252 -497270841
...

correct output
YES
-534092520 -499622905
-532498252 -497270841
-532169300 -496736281
-532312144 -496581113

user output
YES
-534305044 -499782441
-534092520 -499622905
-532312144 -496581113
-531966396 -494582389