Submission details
Task:Broken car race
Sender:¯\_(._.)_/¯
Submission time:2025-11-08 15:45:57 +0200
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#10.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#90.00 sdetails
#100.00 sdetails
#110.00 sdetails
#120.00 sdetails
#130.00 sdetails
#140.00 sdetails
#150.00 sdetails
#160.00 sdetails
#17ACCEPTED0.00 sdetails
#180.00 sdetails
#19ACCEPTED0.01 sdetails
#200.01 sdetails
#21ACCEPTED0.07 sdetails
#220.07 sdetails
#23ACCEPTED0.10 sdetails
#240.10 sdetails
#250.04 sdetails
#260.04 sdetails
#270.05 sdetails
#280.05 sdetails

Code

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

const int mod = 1e9+7;
using P = pair<int, int>;

void printA(P p) { cout << "(" << p.first << " " << p.second << ")\n";}
int inLine(int ax, int ay, int bx, int by, int cx, int cy)
{
    int Ax = bx-ax;
    int Ay = by-ay;
    int Bx = cx-bx;
    int By = cy-by;

    return Ax*By - Bx*Ay;
}

bool order(P p1, P p2, P p3, P p4)
{
    vector<P> Ps = {p1, p2, p3, p4};
    for (int i = 1; i < 4; i++)
    {
        for (int j = 1; j < 4; j++)
        {
            if (j == i)
                continue;
            set<P> used{p2, p3, p4};
            used.erase(Ps[i]);
            used.erase(Ps[j]);
            P last;
            for (P elem : used)
                last = elem;
            // we have Ps[i] Ps[j], last

            int sign1 = inLine(Ps[0].first, Ps[0].second, Ps[i].first, Ps[i].second, Ps[j].first, Ps[j].second);
            int sign2 = inLine(Ps[i].first, Ps[i].second, Ps[j].first, Ps[j].second, last.first, last.second);
            int sign3 = inLine(Ps[j].first, Ps[j].second, last.first, last.second, Ps[0].first, Ps[0].second);

            if ((sign1 <= 0 && sign2 <= 0 && sign3 <= 0) || (sign1 >= 0 && sign2 >= 0 && sign3 >= 0))
            {
                // Found
                return true;
            }
        }
    }
    return false;
}

signed main() {
    int n;
    cin >> n;

    vector<pair<int, int>> dots(n);

    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        dots[i] = {x, y};
    }

    if (n < 4)
    {
        cout << "NO";
        return 0;
    }

    if (n == 4)
    {
        bool res = order(dots[0], dots[1], dots[2], dots[3]);
        if (res)
        {
            cout << "YES\n";
            cout << dots[0].first << " " << dots[0].second << "\n";
            cout << dots[1].first << " " << dots[1].second << "\n";
            cout << dots[2].first << " " << dots[2].second << "\n";
            cout << dots[3].first << " " << dots[3].second << "\n";
        }
        else
        {
            cout << "NO";
        }
        return 0;
    }

    if (n > 4)
    {
        set<P> points = {dots[0], dots[1], dots[2], dots[3], dots[4]};
        for (int i = 0; i < 5; i++)
        {
            set<P> p2 = points;
            p2.erase(dots[i]);

            vector<P> pointArr;
            for (P p : p2)
                pointArr.push_back(p);

            if (order(pointArr[0], pointArr[1], pointArr[2], pointArr[3]))
            {
                cout << "YES\n";
                cout << pointArr[0].first << " " << pointArr[0].second << "\n";
                cout << pointArr[1].first << " " << pointArr[1].second << "\n";
                cout << pointArr[2].first << " " << pointArr[2].second << "\n";
                cout << pointArr[3].first << " " << pointArr[3].second << "\n";
                return 0;
            }
        }
    }
    cout << "NO";
}

Test details

Test 1

Verdict:

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 1
0 1
1 0

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
-1 -999999999
-1000000000 -1000000000
1 -999999999
1000000000 -999999998

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
0 -999999999
-999999999 -1000000000
1 -999999999
1000000000 -999999998

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:

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
2 4
3 4

Test 10

Verdict:

input
4
3 4
0 0
1 1
2 4

correct output
YES
0 0
1 1
3 4
2 4

user output
YES
3 4
0 0
1 1
2 4

Test 11

Verdict:

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
-947475897 -331979444
-947475807 -331979444

Test 12

Verdict:

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

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

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

Test 13

Verdict:

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

correct output
YES
0 0
1 1
3 4
2 4

user output
YES
1 1
2 4
3 4
4 1

Test 14

Verdict:

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
1 1
2 4
3 4

Test 15

Verdict:

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

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

user output
YES
-298761080 -20751868
-298761002 -20751634
-298760924 -20751634
-298760846 -20751868

Test 16

Verdict:

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
-664720316 -463218527
-664720314 -463218521
-664720312 -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
1 1
2 4
3 9
4 16

Test 18

Verdict:

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

correct output
YES
258 979
359 738
961 286
938 1005

user output
YES
359 738
526 210
938 1005
961 286

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
-921893387 -773164998
-921893335 -773164842
-921893283 -773164582
-921893231 -773164218

Test 20

Verdict:

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

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

user output
YES
-857970726 -260438486
-857927295 -260433371
-857907672 -260495123
-857900604 -260453645

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
1 1
2 4
3 9
4 16

Test 22

Verdict:

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

correct output
YES
41172 82734
48266 36871
87910 36263
41280 87283

user output
YES
41172 82734
41280 87283
48266 36871
87910 36263

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
-76010702 -505453310
-76010636 -505453112
-76010570 -505452782
-76010504 -505452320

Test 24

Verdict:

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

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

user output
YES
-234601047 -984160539
-229520466 -983763565
-228868065 -980735452
-228269246 -981952727

Test 25

Verdict:

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
2 4
317 486
448 698

Test 26

Verdict:

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

correct output
YES
32628 54449
40017 12250
59069 42091
62461 59485

user output
YES
40017 12250
59069 42091
62461 59485
63501 56035

Test 27

Verdict:

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
-701962937 -481680975
-701956322 -481670853
-701953571 -481666401

Test 28

Verdict:

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

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

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