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<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int MX = 100005;
ll sq(ll x) { return x*x; }
const pii operator + (const pii &l, const pii &r) { return pii(l.first + r.first, l.second + r.second); }
const pii operator - (const pii &l, const pii &r) { return pii(l.first - r.first, l.second - r.second); }
const pii operator * (const int t, const pii &r) { return pii(t * r.first, t * r.second); }
const ll operator ^ (const pii &l, const pii &r) { return (ll)l.first * r.second - (ll)r.first * l.second; }
ll size(pii c) { return sq(c.first) + sq(c.second); }
bool comp(const pii &l, const pii &r) {
if (r == pii(0, 0)) return false;
if (l == pii(0, 0)) return true;
if ((l^r) != 0) return (l^r) > 0;
else return size(l) < size(r);
}
void convex_hull(const vector<pii> &P, vector<pii> &res)
{
vector<pii> T;
pii mn = P[0];
for (int i = 0; i < P.size(); i++) if (mn > P[i]) mn = P[i];
for (int i = 0; i < P.size(); i++) T.push_back(P[i] - mn);
sort(T.begin(), T.end(), comp);
for (int i = 0; i < T.size(); i++) {
pii c = T[i];
while (res.size() >= 2) {
pii p0 = res.back(), p1 = res[res.size() - 2];
if (((p1 - p0) ^ (c - p0)) >= 0) res.pop_back();
else break;
}
if (!res.size() || res.back() != c) res.push_back(c);
}
for (int i = 0; i < res.size(); i++) res[i] = res[i] + mn;
}
ll furthest_length(const vector<pii> &P)
{
vector<pii> C;
convex_hull(P, C);
C.push_back(C[0]);
ll dist = 0, cur = 1;
for (; cur + 1 < C.size(); cur++) {
ll ccw = (C[0] - C[1]) ^ (C[cur] - C[cur + 1]);
if (ccw <= 0) break;
}
dist = size(C[cur] - C[0]);
for (int i = 1; i + 1 < C.size(); i++) {
for (; cur + 1 < C.size(); cur++) {
ll ccw = (C[i] - C[i + 1]) ^ (C[cur] - C[cur + 1]);
dist = max(size(C[cur] - C[i]), dist);
if (ccw <= 0) break;
}
dist = max(size(C[cur] - C[i]), dist);
}
return dist;
}
ll furthest_length(int N, ll t, pii D[MX], pii V[MX])
{
vector<pii> T(N);
for (int i = 0; i < N; i++) T[i] = D[i] + t * V[i];
return furthest_length(T);
}
int main()
{
static int N, T;
static pii D[MX], V[MX];
scanf("%d%d", &N, &T);
for (int i = 0; i < N; i++) {
scanf("%d%d%d%d", &D[i].first, &D[i].second, &V[i].first, &V[i].second);
}
ll l = 0, r = T, m1, m2;
while (l <= r) {
m1 = (l * 2 + r) / 3;
m2 = (l + r * 2 + 1) / 3;
ll d1 = furthest_length(N, m1, D, V);
ll d2 = furthest_length(N, m2, D, V);
if (d1 <= d2) r = m2 - 1;
else l = m1 + 1;
}
swap(l, r);
printf("%lld\n%lld\n", r, furthest_length(N, r, D, V));
return 0;
}
Compilation message (stderr)
dist.cpp: In function 'void convex_hull(const std::vector<std::pair<int, int> >&, std::vector<std::pair<int, int> >&)':
dist.cpp:30:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < P.size(); i++) if (mn > P[i]) mn = P[i];
^
dist.cpp:31:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < P.size(); i++) T.push_back(P[i] - mn);
^
dist.cpp:34:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < T.size(); i++) {
^
dist.cpp:43:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < res.size(); i++) res[i] = res[i] + mn;
^
dist.cpp: In function 'll furthest_length(const std::vector<std::pair<int, int> >&)':
dist.cpp:53:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (; cur + 1 < C.size(); cur++) {
^
dist.cpp:58:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i + 1 < C.size(); i++) {
^
dist.cpp:59:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (; cur + 1 < C.size(); cur++) {
^
dist.cpp: In function 'int main()':
dist.cpp:81:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &T);
^
dist.cpp:83:72: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &D[i].first, &D[i].second, &V[i].first, &V[i].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... |