This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long N;
cin >> N;
long long X, Y;
cin >> X >> Y;
vector<pair<long long, long long>> Tab;
for (long long i = 0; i < N - 1; i++)
{
long long x, y;
cin >> x >> y;
Tab.push_back({x - X, y - Y});
}
if (N <= 2)
{
cout << -1;
return 0;
}
vector<pair<long long, long long>> Tab2;
for (int i = 0; i < 100; i++)
{
if ((double)Tab[0].first / Tab[1].first != (double)Tab[0].second / Tab[1].second)
break;
random_shuffle(Tab.begin(), Tab.end());
}
while (!Tab.empty() && Tab[0].first == 0)
{
Tab2.push_back(Tab[0]);
swap(Tab[0], Tab[Tab.size() - 1]);
Tab.pop_back();
}
while (Tab.size() > 1)
{
while (Tab.size() > 1 && Tab[1].first == 0)
{
swap(Tab[1], Tab[Tab.size() - 1]);
Tab2.push_back(Tab[Tab.size() - 1]);
Tab.pop_back();
}
if (Tab.size() == 1)
break;
if (abs(Tab[1].first) < abs(Tab[0].first))
swap(Tab[1], Tab[0]);
long long x = Tab[1].first / Tab[0].first;
Tab[1].first -= Tab[0].first * x;
Tab[1].second -= Tab[0].second * x;
if (Tab[1].first == 0 && Tab[1].second != 0)
{
x = Tab[0].second / Tab[1].second;
Tab[0].second -= Tab[1].second * x;
}
}
while (!Tab2.empty() && Tab2[0].second == 0)
{
swap(Tab2[0], Tab2[Tab2.size() - 1]);
Tab2.pop_back();
}
while (Tab2.size() > 1)
{
while (Tab2.size() > 1 && Tab2[1].second == 0)
{
swap(Tab2[1], Tab2[Tab2.size() - 1]);
Tab2.pop_back();
}
if (Tab2.size() == 1)
break;
if (abs(Tab2[1].second) < abs(Tab2[0].second))
swap(Tab2[1], Tab2[0]);
long long x = Tab2[1].second / Tab2[0].second;
Tab2[1].second -= Tab2[0].second * x;
}
if (Tab2.empty())
cout << -1;
else
cout << abs((long long)Tab[0].first * (long long)Tab2[0].second);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |