Submission #151222

# Submission time Handle Problem Language Result Execution time Memory
151222 2019-09-02T09:01:34 Z ChoKang None (KOI16_dist) C++14
100 / 100
661 ms 4492 KB
#include <bits/stdc++.h>
#define MAX_N 30100
#define eb emplace_back
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
struct point{
	ll x, y, dx, dy;
	point(ll x = 0, ll y = 0, ll dx = 0, ll dy = 0): x(x), y(y), dx(dx), dy(dy) {}
};

int n, t;
vector<point> p, e, hull;

int ccw(point a, point b, point c){
	ll val = (b.x-a.x) * (c.y-a.y) - (b.y-a.y) * (c.x-a.x);
	if(val > 0) return 1;
	if(val < 0) return -1;
	return val;
}
bool comp(point p1, point p2){
	int val = ccw(e[0], p1, p2);
	if(val > 0) return true;
	if(val < 0) return false;
	if(p1.x != p2.x) return p1.x < p2.x;
	return p1.y < p2.y;
}
void graham_scan(){
	int Size = 0;
	for(int i = 0; i < n; i++){
		while(Size >= 2 && ccw(hull[Size-2], hull[Size-1], e[i]) <= 0){ Size--; hull.pop_back(); }
		hull.eb(e[i]);
		Size++;
	}
}

ll rotating(int T){

	int pivot = 0;
	for(int i = 0; i < n; i++){
		e.eb(p[i].x + T*p[i].dx, p[i].y + T*p[i].dy, 0, 0);
		if(e[pivot].x > e[i].x || (e[pivot].x == e[i].x && e[pivot].y > e[i].y)) pivot = i;
	}
	
	swap(e[0], e[pivot]);
	sort(e.begin()+1, e.end(), comp);
	graham_scan();

	int Size = hull.size(), ni, nj, j = 1;
	point a, b, c;
	ll ret = 0;

	for(int i = 0; i < Size; i++){
		ni = (i+1)%Size;
		while(1){
			nj = (j+1)%Size;
			a = { 0, 0, 0, 0 };
			b={ hull[ni].x-hull[i].x, hull[ni].y-hull[i].y, 0, 0 };
            c={ hull[nj].x-hull[j].x, hull[nj].y-hull[j].y, 0, 0 };
            int k = ccw(a, b, c);
            if(k > 0) j = nj;
            else break;
		}
		ll val = (hull[i].x - hull[j].x) * (hull[i].x - hull[j].x)
		 			+ (hull[i].y - hull[j].y) * (hull[i].y - hull[j].y);
		ret = max(ret, val);
	}
	e.clear();
	hull.clear();
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> t;

	for(ll i = 0, x1, y1, dx1, dy1; i < n; i++){
		cin >> x1 >> y1 >> dx1 >> dy1;
		p.eb(x1, y1, dx1, dy1);
	}

	int S = 0, E = t;
	ll ans = LLONG_MAX, ind = 0;

	while(S < E){
		int f1 = S +(E-S)/3, f2 = E -(E-S)/3;
		ll val1 = rotating(f1), val2 = rotating(f2);
		if(val1 > val2) S = f1+1;
		else E = f2-1;
	}

	cout << S << endl << rotating(S) <<endl;
	return 0;
}

Compilation message

dist.cpp: In function 'int main()':
dist.cpp:85:5: warning: unused variable 'ans' [-Wunused-variable]
  ll ans = LLONG_MAX, ind = 0;
     ^~~
dist.cpp:85:22: warning: unused variable 'ind' [-Wunused-variable]
  ll ans = LLONG_MAX, ind = 0;
                      ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 252 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 252 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 252 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 252 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 16 ms 376 KB Output is correct
12 Correct 17 ms 504 KB Output is correct
13 Correct 16 ms 248 KB Output is correct
14 Correct 16 ms 380 KB Output is correct
15 Correct 15 ms 504 KB Output is correct
16 Correct 27 ms 552 KB Output is correct
17 Correct 16 ms 504 KB Output is correct
18 Correct 10 ms 376 KB Output is correct
19 Correct 13 ms 424 KB Output is correct
20 Correct 16 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 2796 KB Output is correct
2 Correct 115 ms 3312 KB Output is correct
3 Correct 117 ms 3316 KB Output is correct
4 Correct 123 ms 4464 KB Output is correct
5 Correct 107 ms 3436 KB Output is correct
6 Correct 178 ms 4336 KB Output is correct
7 Correct 92 ms 3324 KB Output is correct
8 Correct 67 ms 3180 KB Output is correct
9 Correct 122 ms 4492 KB Output is correct
10 Correct 116 ms 3436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 252 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 252 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 16 ms 376 KB Output is correct
12 Correct 17 ms 504 KB Output is correct
13 Correct 16 ms 248 KB Output is correct
14 Correct 16 ms 380 KB Output is correct
15 Correct 15 ms 504 KB Output is correct
16 Correct 27 ms 552 KB Output is correct
17 Correct 16 ms 504 KB Output is correct
18 Correct 10 ms 376 KB Output is correct
19 Correct 13 ms 424 KB Output is correct
20 Correct 16 ms 376 KB Output is correct
21 Correct 116 ms 2796 KB Output is correct
22 Correct 115 ms 3312 KB Output is correct
23 Correct 117 ms 3316 KB Output is correct
24 Correct 123 ms 4464 KB Output is correct
25 Correct 107 ms 3436 KB Output is correct
26 Correct 178 ms 4336 KB Output is correct
27 Correct 92 ms 3324 KB Output is correct
28 Correct 67 ms 3180 KB Output is correct
29 Correct 122 ms 4492 KB Output is correct
30 Correct 116 ms 3436 KB Output is correct
31 Correct 612 ms 3444 KB Output is correct
32 Correct 619 ms 3440 KB Output is correct
33 Correct 615 ms 3440 KB Output is correct
34 Correct 594 ms 3436 KB Output is correct
35 Correct 556 ms 3568 KB Output is correct
36 Correct 661 ms 4328 KB Output is correct
37 Correct 544 ms 3564 KB Output is correct
38 Correct 332 ms 3568 KB Output is correct
39 Correct 434 ms 3564 KB Output is correct
40 Correct 605 ms 3440 KB Output is correct
41 Correct 634 ms 4460 KB Output is correct
42 Correct 612 ms 4484 KB Output is correct