#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
using namespace std;
#define square(a) ((a) * (long long)(a))
#define MAX_T 10000000
#define MAX_N 30000
class Star
{
public:
inline void read() {
scanf("%d%d%d%d", &m_org_x, &m_org_y, &m_dx, &m_dy);
}
inline int x() const { return m_x; }
inline int y() const { return m_y; }
inline void calc_coord(int t) {
m_x = m_org_x + t * m_dx;
m_y = m_org_y + t * m_dy;
}
inline long long distance(const Star &other) const {
return square(m_x - other.m_x) + square(m_y - other.m_y);
}
private:
int m_org_x;
int m_org_y;
int m_dx;
int m_dy;
int m_x;
int m_y;
};
class StarStack
{
public:
StarStack() { m_size = 0; }
inline void push(const Star *star) { m_stars[m_size++] = star; }
inline const Star *pop() { return m_stars[--m_size]; }
inline int size() const { return m_size; }
inline const Star& operator[](int n) { return *m_stars[n]; }
inline long long CCW(const Star &P) {
const Star &P1 = *m_stars[m_size - 2];
const Star &P2 = *m_stars[m_size - 1];
return
(P1.x() - P.x()) * (P2.y() - P.y()) -
(P1.y() - P.y()) * (P2.x() - P.x());
}
private:
int m_size;
const Star *m_stars[MAX_N];
};
inline bool operator<(const Star &a, const Star &b) {
if (a.x() < b.x()) return true;
if (a.x() > b.x()) return false;
return a.y() < b.y();
}
bool check_inc_upper(StarStack &UP, StarStack &LO, int i, int j){
return
(UP[i + 1].y() - UP[i].y()) * (LO[j].x() - LO[j - 1].x()) >
(LO[j].y() - LO[j - 1].y()) * (UP[i + 1].x() - UP[i].x());
}
inline long long farthest_distance(Star stars[], int n, int t) {
for (int i = 0; i < n; i++)
stars[i].calc_coord(t);
sort(stars, stars + n);
StarStack UP, LO;
for (int i = 0; i < n; i++) {
while ((UP.size() > 1) && (UP.CCW(stars[i]) >= 0))
UP.pop();
while ((LO.size() > 1) && (LO.CCW(stars[i]) <= 0))
LO.pop();
UP.push(stars + i);
LO.push(stars + i);
}
int i = 0;
int j = LO.size() - 1;
long long farthest = 0;
long long dist;
while ((i < UP.size() - 1) || (j > 0)) {
dist = UP[i].distance(LO[j]);
if (dist > farthest) farthest = dist;
if (i == UP.size() - 1) j--;
else if (j == 0) i++;
else if (check_inc_upper(UP, LO, i, j)) i++;
else j--;
}
dist = UP[i].distance(LO[j]);
if (dist > farthest) farthest = dist;
return farthest;
}
int seek_day(Star stars[], int n, int T) {
int left = 0;
int right = T;
while (left <= right) {
int L = (2 * left + right)/3;
int R = (left + 2 * right + 1)/3;
if (farthest_distance(stars, n, L) <= farthest_distance(stars, n, R))
right = R - 1;
else left = L + 1;
}
return left;
}
int main() {
int n, T;
Star stars[MAX_N];
scanf("%d%d", &n, &T);
for (int i=0; i<n; i++)
stars[i].read();
int day = seek_day(stars, n, T);
long long d = farthest_distance(stars, n, day);
printf("%d\n", day);
printf("%lld\n", d);
return 0;
}
Compilation message
dist.cpp: In function 'int main()':
dist.cpp:132:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &T);
^
dist.cpp: In member function 'void Star::read()':
dist.cpp:16:76: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &m_org_x, &m_org_y, &m_dx, &m_dy);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2168 KB |
Output is correct |
2 |
Correct |
0 ms |
2168 KB |
Output is correct |
3 |
Correct |
0 ms |
2168 KB |
Output is correct |
4 |
Correct |
0 ms |
2164 KB |
Output is correct |
5 |
Correct |
0 ms |
2172 KB |
Output is correct |
6 |
Correct |
0 ms |
2168 KB |
Output is correct |
7 |
Correct |
0 ms |
2164 KB |
Output is correct |
8 |
Correct |
0 ms |
2168 KB |
Output is correct |
9 |
Correct |
0 ms |
2164 KB |
Output is correct |
10 |
Correct |
0 ms |
2164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2168 KB |
Output is correct |
2 |
Correct |
0 ms |
2168 KB |
Output is correct |
3 |
Correct |
0 ms |
2168 KB |
Output is correct |
4 |
Correct |
0 ms |
2164 KB |
Output is correct |
5 |
Correct |
0 ms |
2172 KB |
Output is correct |
6 |
Correct |
0 ms |
2168 KB |
Output is correct |
7 |
Correct |
0 ms |
2164 KB |
Output is correct |
8 |
Correct |
0 ms |
2168 KB |
Output is correct |
9 |
Correct |
0 ms |
2164 KB |
Output is correct |
10 |
Correct |
0 ms |
2164 KB |
Output is correct |
11 |
Incorrect |
3 ms |
2172 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
39 ms |
2172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2168 KB |
Output is correct |
2 |
Correct |
0 ms |
2168 KB |
Output is correct |
3 |
Correct |
0 ms |
2168 KB |
Output is correct |
4 |
Correct |
0 ms |
2164 KB |
Output is correct |
5 |
Correct |
0 ms |
2172 KB |
Output is correct |
6 |
Correct |
0 ms |
2168 KB |
Output is correct |
7 |
Correct |
0 ms |
2164 KB |
Output is correct |
8 |
Correct |
0 ms |
2168 KB |
Output is correct |
9 |
Correct |
0 ms |
2164 KB |
Output is correct |
10 |
Correct |
0 ms |
2164 KB |
Output is correct |
11 |
Incorrect |
3 ms |
2172 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |