답안 #59912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59912 2018-07-23T10:04:19 Z ainta(#1720) Cultivation (JOI17_cultivation) C++11
15 / 100
229 ms 18980 KB
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
int W, H, n, S[610][610], M[610][610], U[610][610];
set<int>SX, SY;
int YY[100000];
struct point {
	int x, y;
}w[330];
struct Rect {
	int x1, y1, x2, y2;
}R[330];
int X[610], Y[610];
bool Pos(int dx, int dy) {
	int i, j;
	int CX = 0, CY = 0;
	for (i = 1; i <= n; i++) {
		X[CX++] = w[i].x;
		X[CX++] = w[i].x + dx + 1;
		Y[CY++] = w[i].y;
		Y[CY++] = w[i].y + dy + 1;
	}
	sort(X, X + CX);
	sort(Y, Y + CY);
	CX = unique(X, X + CX) - X;
	CY = unique(Y, Y + CY) - Y;
	for (i = 0; i <= CX; i++)for (j = 0; j <= CY; j++)S[i][j] = 0;
	for (i = 1; i <= n; i++) {
		R[i].x1 = lower_bound(X, X + CX, w[i].x) - X;
		R[i].x2 = lower_bound(X, X + CX, w[i].x + dx + 1) - X;
		R[i].y1 = lower_bound(Y, Y + CY, w[i].y) - Y;
		R[i].y2 = lower_bound(Y, Y + CY, w[i].y + dy + 1) - Y;
		S[R[i].x1][R[i].y1]++;
		S[R[i].x1][R[i].y2]--;
		S[R[i].x2][R[i].y1]--;
		S[R[i].x2][R[i].y2]++;
	}
	for (i = 0; i < CX; i++)for (j = 1; j < CY; j++)S[i][j] += S[i][j - 1];
	for (i = 1; i < CX; i++)for (j = 0; j < CY; j++)S[i][j] += S[i -1][j];
	for (i = 0; i < CX - 1; i++) {
		for (j = 0; j < CY - 1; j++) {
			if (!S[i][j])M[i][j] = 0;
			else if (j == 0)M[i][j] = Y[j + 1] - Y[j];
			else M[i][j] = Y[j + 1] - Y[j] + M[i][j - 1];
			if (M[i][j] >= H) {
				if (i == 0)U[i][j] = X[i + 1] - X[i];
				else U[i][j] = U[i - 1][j] + X[i + 1] - X[i];
				if (U[i][j] >= W)return true;
			}
			else {
				U[i][j] = 0;
			}
		}
	}
	return false;
}
int main() {
	int i, j, CY = 0;
	scanf("%d%d%d", &W, &H, &n);
	for (i = 1; i <= n; i++) {
		scanf("%d%d", &w[i].x, &w[i].y);
	}
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			if (w[i].x <= w[j].x) {
				if(w[j].x>w[i].x)SX.insert(w[j].x - w[i].x - 1);
				SX.insert(w[i].x - 1 + W - w[j].x);
			}
			SX.insert(w[j].x - w[i].x + W);
			if (w[i].y <= w[j].y) {
				if (w[j].y>w[i].y)SY.insert(w[j].y - w[i].y - 1);
				SY.insert(w[i].y - 1 + H - w[j].y);
			}
			SY.insert(w[j].y - w[i].y + H);
		}
	}
	int res = 1e9;
	for (auto &y : SY) {
		YY[CY++] = y;
	}
	for (auto &x : SX) {
		int b = 0, e = CY - 1, r = CY;
		while (b <= e) {
			int mid = (b + e) >> 1;
			if (Pos(x, YY[mid])) {
				r = mid;
				e = mid - 1;
			}
			else b = mid + 1;
		}
		if (r != CY) {
			res = min(res, x + YY[r]);
		}
	}
	printf("%d\n", res);
	return 0;
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &W, &H, &n);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &w[i].x, &w[i].y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 3 ms 448 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 3 ms 528 KB Output is correct
8 Correct 3 ms 536 KB Output is correct
9 Correct 3 ms 536 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 2 ms 820 KB Output is correct
15 Correct 3 ms 820 KB Output is correct
16 Correct 2 ms 820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 3 ms 448 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 3 ms 528 KB Output is correct
8 Correct 3 ms 536 KB Output is correct
9 Correct 3 ms 536 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 2 ms 820 KB Output is correct
15 Correct 3 ms 820 KB Output is correct
16 Correct 2 ms 820 KB Output is correct
17 Correct 3 ms 888 KB Output is correct
18 Correct 10 ms 892 KB Output is correct
19 Correct 9 ms 892 KB Output is correct
20 Correct 3 ms 892 KB Output is correct
21 Correct 19 ms 1020 KB Output is correct
22 Correct 44 ms 1148 KB Output is correct
23 Correct 6 ms 1148 KB Output is correct
24 Correct 55 ms 1148 KB Output is correct
25 Correct 41 ms 1148 KB Output is correct
26 Correct 68 ms 1148 KB Output is correct
27 Correct 78 ms 1344 KB Output is correct
28 Correct 56 ms 1344 KB Output is correct
29 Correct 70 ms 1344 KB Output is correct
30 Correct 79 ms 1344 KB Output is correct
31 Correct 75 ms 1344 KB Output is correct
32 Correct 75 ms 1344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 3 ms 448 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 3 ms 528 KB Output is correct
8 Correct 3 ms 536 KB Output is correct
9 Correct 3 ms 536 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 2 ms 820 KB Output is correct
15 Correct 3 ms 820 KB Output is correct
16 Correct 2 ms 820 KB Output is correct
17 Correct 3 ms 888 KB Output is correct
18 Correct 10 ms 892 KB Output is correct
19 Correct 9 ms 892 KB Output is correct
20 Correct 3 ms 892 KB Output is correct
21 Correct 19 ms 1020 KB Output is correct
22 Correct 44 ms 1148 KB Output is correct
23 Correct 6 ms 1148 KB Output is correct
24 Correct 55 ms 1148 KB Output is correct
25 Correct 41 ms 1148 KB Output is correct
26 Correct 68 ms 1148 KB Output is correct
27 Correct 78 ms 1344 KB Output is correct
28 Correct 56 ms 1344 KB Output is correct
29 Correct 70 ms 1344 KB Output is correct
30 Correct 79 ms 1344 KB Output is correct
31 Correct 75 ms 1344 KB Output is correct
32 Correct 75 ms 1344 KB Output is correct
33 Runtime error 197 ms 18980 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 18980 KB Output is correct
2 Incorrect 229 ms 18980 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 18980 KB Output is correct
2 Incorrect 229 ms 18980 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 3 ms 448 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 3 ms 528 KB Output is correct
8 Correct 3 ms 536 KB Output is correct
9 Correct 3 ms 536 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 2 ms 820 KB Output is correct
15 Correct 3 ms 820 KB Output is correct
16 Correct 2 ms 820 KB Output is correct
17 Correct 3 ms 888 KB Output is correct
18 Correct 10 ms 892 KB Output is correct
19 Correct 9 ms 892 KB Output is correct
20 Correct 3 ms 892 KB Output is correct
21 Correct 19 ms 1020 KB Output is correct
22 Correct 44 ms 1148 KB Output is correct
23 Correct 6 ms 1148 KB Output is correct
24 Correct 55 ms 1148 KB Output is correct
25 Correct 41 ms 1148 KB Output is correct
26 Correct 68 ms 1148 KB Output is correct
27 Correct 78 ms 1344 KB Output is correct
28 Correct 56 ms 1344 KB Output is correct
29 Correct 70 ms 1344 KB Output is correct
30 Correct 79 ms 1344 KB Output is correct
31 Correct 75 ms 1344 KB Output is correct
32 Correct 75 ms 1344 KB Output is correct
33 Runtime error 197 ms 18980 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Halted 0 ms 0 KB -