Submission #153240

# Submission time Handle Problem Language Result Execution time Memory
153240 2019-09-13T02:01:00 Z gs18103 None (KOI16_dist) C++14
100 / 100
717 ms 3668 KB
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
 
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;
 
ll arr[30303][4];
pll base;
int n, T;

ll ccw(pll a, pll b, pll c) {
	return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}

ll dis(pll a, pll b) {
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

ll cal_dis(int t) {
	vector <pll> p, ch;
	for(int i = 0; i < n; i++) {
		p.emplace_back(arr[i][0] + arr[i][2] * (ll)t, arr[i][1] + arr[i][3] * (ll)t);
	}
	sort(all(p));
	p.erase(unique(all(p)), p.end());
	if(p.size() == 1) return 0;
	base = p[0];
	sort(p.begin()+1, p.end(), [](pll a, pll b) {
		if(ccw(base, a, b) == 0) return dis(base, a) < dis(base, b);
		return ccw(base, a, b) > 0;
	});
	ch.push_back(base);
	for(int i = 1; i < p.size(); i++) {
		while(ch.size() >= 2) {
			pll p1 = ch[ch.size()-2], p2 = ch[ch.size()-1];
			if(ccw(p1, p2, p[i]) > 0) break;
			ch.pop_back();
		}
		ch.push_back(p[i]);
	}

	ll ret = 0;
	for(int i = 0; i < ch.size(); i++) {
		if(i+1 < ch.size() && ch[i+1].x < ch[i].x) break;
		int lb = i, ub = ch.size()-1;
		while(lb + 10 < ub) {
			int m1 = (2 * lb + ub) / 3, m2 = (lb + 2 * ub) / 3;
			if(dis(ch[m1], ch[i]) > dis(ch[m2], ch[i])) ub = m2;
			else lb = m1;
		}
		for(int j = lb; j <= ub; j++) {
			if(dis(ch[i], ch[lb]) < dis(ch[i], ch[j])) lb = j;
		}
		ret = max(ret, dis(ch[i], ch[lb]));
	}
	return ret;
}

int search(int s, int e) {
	if(s + 10 >= e) 	{
		ll dis = 9000000000000000000LL;
		for(int i = s; i <= e; i++) {
			dis = min(dis, cal_dis(i));
		}
		for(int i = s; i <= e; i++) {
			if(dis == cal_dis(i)) return i;
		}
	}
	int t1 = (2 * s + e) / 3, t2 = (s + 2 * e) / 3;
	ll dis1 = cal_dis(t1), dis2 = cal_dis(t2);
	if(dis1 <= dis2) return search(s, t2);
	else return search(t1, e);
}
 
int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> T;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 4; j++) {
			cin >> arr[i][j];
		}
	}
	int ans = search(0, T);
	cout << ans << endl << cal_dis(ans);
}

Compilation message

dist.cpp: In function 'll cal_dis(int)':
dist.cpp:36:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < p.size(); i++) {
                 ~~^~~~~~~~~~
dist.cpp:46:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ch.size(); i++) {
                 ~~^~~~~~~~~~~
dist.cpp:47:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i+1 < ch.size() && ch[i+1].x < ch[i].x) break;
      ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 292 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 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 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 292 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 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 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 16 ms 508 KB Output is correct
12 Correct 19 ms 376 KB Output is correct
13 Correct 15 ms 380 KB Output is correct
14 Correct 17 ms 376 KB Output is correct
15 Correct 11 ms 380 KB Output is correct
16 Correct 18 ms 376 KB Output is correct
17 Correct 11 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 13 ms 504 KB Output is correct
20 Correct 16 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 217 ms 2432 KB Output is correct
2 Correct 158 ms 2396 KB Output is correct
3 Correct 167 ms 2448 KB Output is correct
4 Correct 146 ms 2760 KB Output is correct
5 Correct 167 ms 2304 KB Output is correct
6 Correct 158 ms 3400 KB Output is correct
7 Correct 99 ms 2792 KB Output is correct
8 Correct 52 ms 2688 KB Output is correct
9 Correct 159 ms 3500 KB Output is correct
10 Correct 218 ms 3076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 292 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 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 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 16 ms 508 KB Output is correct
12 Correct 19 ms 376 KB Output is correct
13 Correct 15 ms 380 KB Output is correct
14 Correct 17 ms 376 KB Output is correct
15 Correct 11 ms 380 KB Output is correct
16 Correct 18 ms 376 KB Output is correct
17 Correct 11 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 13 ms 504 KB Output is correct
20 Correct 16 ms 376 KB Output is correct
21 Correct 217 ms 2432 KB Output is correct
22 Correct 158 ms 2396 KB Output is correct
23 Correct 167 ms 2448 KB Output is correct
24 Correct 146 ms 2760 KB Output is correct
25 Correct 167 ms 2304 KB Output is correct
26 Correct 158 ms 3400 KB Output is correct
27 Correct 99 ms 2792 KB Output is correct
28 Correct 52 ms 2688 KB Output is correct
29 Correct 159 ms 3500 KB Output is correct
30 Correct 218 ms 3076 KB Output is correct
31 Correct 651 ms 3180 KB Output is correct
32 Correct 617 ms 3016 KB Output is correct
33 Correct 616 ms 2888 KB Output is correct
34 Correct 637 ms 3096 KB Output is correct
35 Correct 452 ms 3128 KB Output is correct
36 Correct 653 ms 3412 KB Output is correct
37 Correct 417 ms 3104 KB Output is correct
38 Correct 144 ms 3040 KB Output is correct
39 Correct 512 ms 3108 KB Output is correct
40 Correct 634 ms 3172 KB Output is correct
41 Correct 717 ms 3600 KB Output is correct
42 Correct 611 ms 3668 KB Output is correct