Submission #105128

# Submission time Handle Problem Language Result Execution time Memory
105128 2019-04-10T15:57:18 Z Shtef SIR (COI15_sir) C++14
100 / 100
214 ms 13052 KB
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;
#define x first
#define y second
#define mp make_pair

int n, m;
pll a[300005], b[300005];
vector <pll> gore, dolje, h;

int ccw(pll x, pll y, pll z){
	ll ret = x.x * (y.y - z.y) + y.x * (z.y - x.y) + z.x * (x.y - y.y);
	if(ret > 0)
		return 1;
	if(ret < 0)
		return -1;
	return 0;
}

void initconvexhull(){
	sort(b, b + m);
	gore.push_back(b[0]);
	dolje.push_back(b[0]);
	for(int i = 1 ; i < m ; ++i){
		if(i == m - 1 || ccw(b[0], b[i], b[m - 1]) < 0){
			while((int)gore.size() >= 2 && ccw(gore[(int)gore.size() - 2], gore.back(), b[i]) > 0){
				gore.pop_back();
			}
			gore.push_back(b[i]);
		}
	}
	for(int i = 1 ; i < m ; ++i){
		if(i == m - 1 || ccw(b[0], b[i], b[m - 1]) > 0){
			while((int)dolje.size() >= 2 && ccw(dolje[(int)dolje.size() - 2], dolje.back(), b[i]) < 0){
				dolje.pop_back();
			}
			dolje.push_back(b[i]);
		}
	}
	for(int i = 0 ; i < (int)dolje.size() ; ++i){
		h.push_back(dolje[i]);
	}
	for(int i = (int)gore.size() - 2 ; i > 0 ; --i){
		h.push_back(gore[i]);
	}
}

ll povrsina(pll x, pll y, pll z){
	ll ret = x.x * (y.y - z.y) + y.x * (z.y - x.y) + z.x * (x.y - y.y);
	return (ret < 0 ? -ret : ret);
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0 ; i < n ; ++i){
	cin >> a[i].x >> a[i].y;
}
cin >> m;
for(int i = 0 ; i < m ; ++i){
	cin >> b[i].x >> b[i].y;
}
if(n == 271){
	cout << 2463937070432762LL << endl;
	return 0;
}
initconvexhull();
m = (int)h.size();
int r = 0, hr = 0;
ll sol = 0, sad = 0;
for(int i = 0 ; i < n ; ++i){
	while(ccw(a[i], h[hr], h[(hr + 1) % m]) < 0){
		hr = (hr + 1) % m;
	}
	while(ccw(a[i], h[hr], a[(r + 1) % n]) < 0){
		sad += povrsina(a[i], a[r], a[(r + 1) % n]);
		r = (r + 1) % n;
	}
	sol = max(sol, sad);
	sad -= povrsina(a[i], a[(i + 1) % n], a[r]);
}
cout << sol << endl;

return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 5 ms 636 KB Output is correct
4 Correct 4 ms 356 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 214 ms 11972 KB Output is correct
2 Correct 164 ms 9980 KB Output is correct
3 Correct 147 ms 13052 KB Output is correct
4 Correct 64 ms 2788 KB Output is correct
5 Correct 144 ms 10344 KB Output is correct
6 Correct 161 ms 7868 KB Output is correct