답안 #549142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549142 2022-04-15T09:53:32 Z kingfran1907 SIR (COI15_sir) C++14
0 / 100
159 ms 15756 KB
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 3e5+10;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;

int n, m;
pair<int, int> niz[maxn], ss[maxn];
vector< int > hul, hul2;
vector< pair<int, int> > hull;
bool bio[maxn];

llint ccw(pair<int, int> a, pair<int, int> b, pair<int, int> c) {
	return (llint)a.X * (b.Y - c.Y) + (llint)b.X * (c.Y - a.Y) + (llint)c.X * (a.Y - b.Y);
}

llint dist(pair<int, int> a, pair<int, int> b) {
	return (llint) (a.X - b.X) * (a.X - b.X) + (llint) (a.Y - b.Y) * (a.Y - b.Y);
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		niz[i] = {x, y};
	}

	scanf("%d", &m);
	for (int i = 0; i < m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		ss[i] = {x, y};
	}

	sort(ss, ss + m);
	for (int i = 0; i < m; i++) {
		while (hul.size() >= 2 && ccw(ss[hul[hul.size() - 2]], ss[hul.back()], ss[i]) >= 0) 
			hul.pop_back();
		hul.push_back(i);
	}

	//printf("debug: \n");
	//for (int i = 0; i < hul.size(); i++) {
	//	printf("%d %d\n", ss[hul[i]].X, ss[hul[i]].Y);
	//}

	reverse(ss, ss + m);
	for (int i = 0; i < m; i++) {
		while (hul2.size() >= 2 && ccw(ss[hul2[hul2.size() - 2]], ss[hul2.back()], ss[i]) >= 0)
			hul2.pop_back();
		hul2.push_back(i);
	}

	//printf("debug: \n");
	//for (int i = 0; i < hul2.size(); i++) {
	//	printf("%d %d\n", ss[hul2[i]].X, ss[hul2[i]].Y);
	//}

	reverse(hul2.begin(), hul2.end());
	reverse(ss, ss + m);
	for (int tren : hul2) hul.push_back(m - 1 - tren);
	memset(bio, false, sizeof bio);
	for (int i = 0; i < hul.size(); i++) {
		if (!bio[hul[i]]) hull.push_back(ss[hul[i]]);
		bio[hul[i]] = true;
	}
	reverse(hull.begin(), hull.end());

	//for (int i = 0; i < hull.size(); i++) {
	//	printf("(%d %d) ", hull[i].X, hull[i].Y);
	//}
	//printf("\n");

	int ptr = 0;
	int ptrh = 0;
	for (int i = 0; i < hull.size(); i++) {
		if (dist(niz[0], hull[i]) < dist(niz[0], hull[ptrh]))
			ptrh = i;
	}
	//printf("starting ptrh: %d\n", ptrh);

	int siz = hull.size();
	llint sol = 0;
	llint tren = 0;
	for (int i = 0; i < n; i++) {
		//printf("trying: %d\n", i);
		//printf("ccw: %lld (%d %d) (%d %d)\n", ccw(niz[i], hull[ptrh], hull[(ptrh + 1) % siz]), hull[ptrh].X, hull[ptrh].Y, hull[(ptrh + 1) % siz].X, hull[(ptrh + 1) % siz].Y);
		while (ccw(niz[i], hull[ptrh], hull[(ptrh + 1) % siz]) < 0) {
			ptrh++;
			if (ptrh == siz) ptrh = 0; 
			//printf("ptrh: %d\n", ptrh);
		}

		while (ccw(niz[i], hull[ptrh], niz[(ptr + 1) % n]) < 0) {
			tren += ccw(niz[i], niz[ptr], niz[(ptr + 1) % n]);
			sol = max(sol, tren);
			ptr++;
			if (ptr == n) ptr = 0;
			//printf("ptr: %d (%lld)\n", ptr, tren);
		}
		tren -= ccw(niz[i], niz[(i + 1) % n], niz[ptr]);
		sol = max(sol, tren);
		//printf("removing: %lld\n", tren);
	}
	printf("%lld\n", sol);
	return 0;
}

Compilation message

sir.cpp: In function 'int main()':
sir.cpp:73:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for (int i = 0; i < hul.size(); i++) {
      |                  ~~^~~~~~~~~~~~
sir.cpp:86:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |  for (int i = 0; i < hull.size(); i++) {
      |                  ~~^~~~~~~~~~~~~
sir.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
sir.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |   scanf("%d%d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~
sir.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d", &m);
      |  ~~~~~^~~~~~~~~~
sir.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%d%d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 159 ms 15756 KB Output isn't correct
2 Halted 0 ms 0 KB -