#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int ll
using pii = pair <int, int>;
#define INF 0x7f7f7f7f7f7f7f7f
const bool debug = 0;
struct point
{
int x, y, dx, dy;
point operator+(const point &other)
{
return {x+other.x, y+other.y};
}
point operator-(const point &other)
{
return {x-other.x, y-other.y};
}
point operator*(const int C)
{
return {x*C, y*C, dx, dy};
}
int normsq()
{
return x*x+y*y;
}
};
int dist(point &a, point &b)
{
return (a-b).normsq();
}
class convex_hull
{
public:
int n;
static int ccw (point a, point b, point c)
{
int v = (b.x - a.x) * (c.y - a.y) - (b.y-a.y)*(c.x-a.x);
if (v > 0) return 1;
if (!v) return 0;
return -1;
}
static bool compy (point &a, point &b)
{
if (a.y == b.y) return a.x < b.x;
return a.y < b.y;
}
vector <point> pt;
vector <point> convex;
void graham_scan()
{
convex.clear();
sort(all(pt), compy);
point down = pt[0];
sort(all(pt), [&down](auto a, auto b)
{
int u = ccw(down, a, b);
if (u!=0) return u>0;
else return dist(down, a) < dist(down, b);
});
convex.push_back(pt[0]);
convex.push_back(pt[1]);
for (int i = 2; i<n; i++)
{
while(convex.size() > 1)
{
point tp = convex.back();
convex.pop_back();
point tptp = convex.back();
if (ccw(tptp,tp,pt[i]) > 0)
{
convex.push_back(tp);
break;
}
}
convex.push_back(pt[i]);
}
}
int rotating_calipers()
{
int msz = 0;
int t = 0;
point o = {0, 0};
int nc = convex.size();
for(int i=0; i<convex.size(); i++)
{
while(t+1 < convex.size() && ccw(o, convex[i+1]-convex[i], convex[t+1]-convex[t])>=0)
{
if (msz < dist(convex[i], convex[t]))
msz = dist(convex[i], convex[t]);
t++;
}
if (msz < dist(convex[i], convex[t]))
msz = dist(convex[i], convex[t]);
}
return msz;
}
};
convex_hull C;
vector <point> ptt;
int n, t;
int func(int x)
{
C.pt.clear();
for (int i = 0; i<n; i++)
C.pt.push_back({ptt[i].x+ptt[i].dx*x, ptt[i].y+ptt[i].dy*x,0,0});
C.graham_scan();
int u = C.rotating_calipers();
return u;
}
int32_t main()
{
usecppio
cin >> n >> t;
C.n = n;
for (int i = 0; i<n; i++)
{
int a, b, c, d;
cin >> a >> b >> c >> d;
ptt.push_back({a, b, c, d});
}
int lo = 0, hi = t;
while(lo + 3 <= hi)
{
int m1 = (2*lo+hi)/3;
int m2 = (lo+2*hi)/3;
if (func(m1) > func(m2))
lo = m1;
else hi = m2;
}
int ind = lo;
int best = func(lo);
for (int i = lo; i<=hi; i++)
{
int cur = func(i);
if (cur < best)
{
best = cur;
ind = i;
}
}
cout << ind << '\n';
cout << best << '\n';
}
Compilation message
dist.cpp: In member function 'long long int convex_hull::rotating_calipers()':
dist.cpp:92:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<convex.size(); i++)
~^~~~~~~~~~~~~~
dist.cpp:94:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(t+1 < convex.size() && ccw(o, convex[i+1]-convex[i], convex[t+1]-convex[t])>=0)
~~~~^~~~~~~~~~~~~~~
dist.cpp:91:13: warning: unused variable 'nc' [-Wunused-variable]
int nc = convex.size();
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
24 ms |
384 KB |
Output is correct |
12 |
Correct |
24 ms |
512 KB |
Output is correct |
13 |
Correct |
23 ms |
384 KB |
Output is correct |
14 |
Correct |
24 ms |
384 KB |
Output is correct |
15 |
Correct |
26 ms |
384 KB |
Output is correct |
16 |
Correct |
21 ms |
512 KB |
Output is correct |
17 |
Correct |
23 ms |
384 KB |
Output is correct |
18 |
Correct |
19 ms |
512 KB |
Output is correct |
19 |
Correct |
22 ms |
504 KB |
Output is correct |
20 |
Correct |
25 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
208 ms |
2808 KB |
Output is correct |
2 |
Correct |
188 ms |
2808 KB |
Output is correct |
3 |
Correct |
191 ms |
2808 KB |
Output is correct |
4 |
Correct |
142 ms |
3696 KB |
Output is correct |
5 |
Correct |
230 ms |
2808 KB |
Output is correct |
6 |
Correct |
160 ms |
3832 KB |
Output is correct |
7 |
Correct |
164 ms |
2764 KB |
Output is correct |
8 |
Correct |
153 ms |
2808 KB |
Output is correct |
9 |
Correct |
163 ms |
3828 KB |
Output is correct |
10 |
Correct |
204 ms |
2936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
24 ms |
384 KB |
Output is correct |
12 |
Correct |
24 ms |
512 KB |
Output is correct |
13 |
Correct |
23 ms |
384 KB |
Output is correct |
14 |
Correct |
24 ms |
384 KB |
Output is correct |
15 |
Correct |
26 ms |
384 KB |
Output is correct |
16 |
Correct |
21 ms |
512 KB |
Output is correct |
17 |
Correct |
23 ms |
384 KB |
Output is correct |
18 |
Correct |
19 ms |
512 KB |
Output is correct |
19 |
Correct |
22 ms |
504 KB |
Output is correct |
20 |
Correct |
25 ms |
384 KB |
Output is correct |
21 |
Correct |
208 ms |
2808 KB |
Output is correct |
22 |
Correct |
188 ms |
2808 KB |
Output is correct |
23 |
Correct |
191 ms |
2808 KB |
Output is correct |
24 |
Correct |
142 ms |
3696 KB |
Output is correct |
25 |
Correct |
230 ms |
2808 KB |
Output is correct |
26 |
Correct |
160 ms |
3832 KB |
Output is correct |
27 |
Correct |
164 ms |
2764 KB |
Output is correct |
28 |
Correct |
153 ms |
2808 KB |
Output is correct |
29 |
Correct |
163 ms |
3828 KB |
Output is correct |
30 |
Correct |
204 ms |
2936 KB |
Output is correct |
31 |
Correct |
914 ms |
2936 KB |
Output is correct |
32 |
Correct |
854 ms |
2936 KB |
Output is correct |
33 |
Correct |
848 ms |
2936 KB |
Output is correct |
34 |
Correct |
830 ms |
2936 KB |
Output is correct |
35 |
Correct |
972 ms |
2936 KB |
Output is correct |
36 |
Correct |
749 ms |
3944 KB |
Output is correct |
37 |
Correct |
803 ms |
2928 KB |
Output is correct |
38 |
Correct |
636 ms |
2936 KB |
Output is correct |
39 |
Correct |
647 ms |
2936 KB |
Output is correct |
40 |
Correct |
865 ms |
2928 KB |
Output is correct |
41 |
Correct |
725 ms |
3824 KB |
Output is correct |
42 |
Correct |
829 ms |
4592 KB |
Output is correct |