#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
long long W, H, n, S[610][610], M[610][610], U[610][610];
set<long long>SX, SY;
long long YY[1000000];
struct point {
long long x, y;
}w[330];
struct Rect {
long long x1, y1, x2, y2;
}R[330];
long long X[610], Y[610];
bool Pos(long long dx, long long dy) {
long long i, j;
long long 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() {
//freopen("input.txt", "r", stdin);
long long i, j, CY = 0;
scanf("%lld%lld%lld", &W, &H, &n);
for (i = 1; i <= n; i++) {
scanf("%lld%lld", &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);
}
}
long long res = 4e9;
for (auto &y : SY) {
YY[CY++] = y;
}
for (auto &x : SX) {
long long b = 0, e = CY - 1, r = CY;
while (b <= e) {
long long 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("%lld\n", res);
return 0;
}
Compilation message
cultivation.cpp: In function 'int main()':
cultivation.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld", &W, &H, &n);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &w[i].x, &w[i].y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
436 KB |
Output is correct |
3 |
Correct |
3 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
608 KB |
Output is correct |
5 |
Correct |
3 ms |
608 KB |
Output is correct |
6 |
Correct |
2 ms |
608 KB |
Output is correct |
7 |
Correct |
3 ms |
608 KB |
Output is correct |
8 |
Correct |
3 ms |
628 KB |
Output is correct |
9 |
Correct |
3 ms |
628 KB |
Output is correct |
10 |
Correct |
2 ms |
628 KB |
Output is correct |
11 |
Correct |
3 ms |
628 KB |
Output is correct |
12 |
Correct |
2 ms |
628 KB |
Output is correct |
13 |
Correct |
2 ms |
628 KB |
Output is correct |
14 |
Correct |
3 ms |
696 KB |
Output is correct |
15 |
Correct |
3 ms |
696 KB |
Output is correct |
16 |
Correct |
2 ms |
696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
436 KB |
Output is correct |
3 |
Correct |
3 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
608 KB |
Output is correct |
5 |
Correct |
3 ms |
608 KB |
Output is correct |
6 |
Correct |
2 ms |
608 KB |
Output is correct |
7 |
Correct |
3 ms |
608 KB |
Output is correct |
8 |
Correct |
3 ms |
628 KB |
Output is correct |
9 |
Correct |
3 ms |
628 KB |
Output is correct |
10 |
Correct |
2 ms |
628 KB |
Output is correct |
11 |
Correct |
3 ms |
628 KB |
Output is correct |
12 |
Correct |
2 ms |
628 KB |
Output is correct |
13 |
Correct |
2 ms |
628 KB |
Output is correct |
14 |
Correct |
3 ms |
696 KB |
Output is correct |
15 |
Correct |
3 ms |
696 KB |
Output is correct |
16 |
Correct |
2 ms |
696 KB |
Output is correct |
17 |
Correct |
4 ms |
936 KB |
Output is correct |
18 |
Correct |
13 ms |
1324 KB |
Output is correct |
19 |
Correct |
7 ms |
1324 KB |
Output is correct |
20 |
Correct |
3 ms |
1324 KB |
Output is correct |
21 |
Correct |
14 ms |
1408 KB |
Output is correct |
22 |
Correct |
38 ms |
1860 KB |
Output is correct |
23 |
Correct |
7 ms |
1860 KB |
Output is correct |
24 |
Correct |
54 ms |
1860 KB |
Output is correct |
25 |
Correct |
51 ms |
1860 KB |
Output is correct |
26 |
Correct |
89 ms |
1876 KB |
Output is correct |
27 |
Correct |
75 ms |
1880 KB |
Output is correct |
28 |
Correct |
48 ms |
1880 KB |
Output is correct |
29 |
Correct |
66 ms |
1880 KB |
Output is correct |
30 |
Correct |
78 ms |
1880 KB |
Output is correct |
31 |
Correct |
82 ms |
1880 KB |
Output is correct |
32 |
Correct |
75 ms |
1880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
436 KB |
Output is correct |
3 |
Correct |
3 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
608 KB |
Output is correct |
5 |
Correct |
3 ms |
608 KB |
Output is correct |
6 |
Correct |
2 ms |
608 KB |
Output is correct |
7 |
Correct |
3 ms |
608 KB |
Output is correct |
8 |
Correct |
3 ms |
628 KB |
Output is correct |
9 |
Correct |
3 ms |
628 KB |
Output is correct |
10 |
Correct |
2 ms |
628 KB |
Output is correct |
11 |
Correct |
3 ms |
628 KB |
Output is correct |
12 |
Correct |
2 ms |
628 KB |
Output is correct |
13 |
Correct |
2 ms |
628 KB |
Output is correct |
14 |
Correct |
3 ms |
696 KB |
Output is correct |
15 |
Correct |
3 ms |
696 KB |
Output is correct |
16 |
Correct |
2 ms |
696 KB |
Output is correct |
17 |
Correct |
4 ms |
936 KB |
Output is correct |
18 |
Correct |
13 ms |
1324 KB |
Output is correct |
19 |
Correct |
7 ms |
1324 KB |
Output is correct |
20 |
Correct |
3 ms |
1324 KB |
Output is correct |
21 |
Correct |
14 ms |
1408 KB |
Output is correct |
22 |
Correct |
38 ms |
1860 KB |
Output is correct |
23 |
Correct |
7 ms |
1860 KB |
Output is correct |
24 |
Correct |
54 ms |
1860 KB |
Output is correct |
25 |
Correct |
51 ms |
1860 KB |
Output is correct |
26 |
Correct |
89 ms |
1876 KB |
Output is correct |
27 |
Correct |
75 ms |
1880 KB |
Output is correct |
28 |
Correct |
48 ms |
1880 KB |
Output is correct |
29 |
Correct |
66 ms |
1880 KB |
Output is correct |
30 |
Correct |
78 ms |
1880 KB |
Output is correct |
31 |
Correct |
82 ms |
1880 KB |
Output is correct |
32 |
Correct |
75 ms |
1880 KB |
Output is correct |
33 |
Correct |
285 ms |
13040 KB |
Output is correct |
34 |
Correct |
874 ms |
13876 KB |
Output is correct |
35 |
Correct |
333 ms |
13876 KB |
Output is correct |
36 |
Correct |
893 ms |
14328 KB |
Output is correct |
37 |
Correct |
690 ms |
14328 KB |
Output is correct |
38 |
Correct |
899 ms |
14336 KB |
Output is correct |
39 |
Correct |
735 ms |
14336 KB |
Output is correct |
40 |
Correct |
850 ms |
14364 KB |
Output is correct |
41 |
Correct |
670 ms |
14364 KB |
Output is correct |
42 |
Correct |
333 ms |
14364 KB |
Output is correct |
43 |
Correct |
765 ms |
14364 KB |
Output is correct |
44 |
Correct |
391 ms |
14364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
14364 KB |
Output is correct |
2 |
Correct |
256 ms |
14364 KB |
Output is correct |
3 |
Correct |
321 ms |
14364 KB |
Output is correct |
4 |
Correct |
289 ms |
14364 KB |
Output is correct |
5 |
Correct |
317 ms |
14364 KB |
Output is correct |
6 |
Correct |
25 ms |
14364 KB |
Output is correct |
7 |
Correct |
12 ms |
14364 KB |
Output is correct |
8 |
Correct |
303 ms |
14364 KB |
Output is correct |
9 |
Correct |
102 ms |
14364 KB |
Output is correct |
10 |
Correct |
315 ms |
14364 KB |
Output is correct |
11 |
Correct |
295 ms |
14364 KB |
Output is correct |
12 |
Correct |
302 ms |
14364 KB |
Output is correct |
13 |
Correct |
27 ms |
14364 KB |
Output is correct |
14 |
Correct |
83 ms |
14364 KB |
Output is correct |
15 |
Correct |
26 ms |
14364 KB |
Output is correct |
16 |
Correct |
282 ms |
14364 KB |
Output is correct |
17 |
Correct |
289 ms |
14364 KB |
Output is correct |
18 |
Correct |
114 ms |
14364 KB |
Output is correct |
19 |
Correct |
311 ms |
14364 KB |
Output is correct |
20 |
Correct |
320 ms |
14364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
14364 KB |
Output is correct |
2 |
Correct |
256 ms |
14364 KB |
Output is correct |
3 |
Correct |
321 ms |
14364 KB |
Output is correct |
4 |
Correct |
289 ms |
14364 KB |
Output is correct |
5 |
Correct |
317 ms |
14364 KB |
Output is correct |
6 |
Correct |
25 ms |
14364 KB |
Output is correct |
7 |
Correct |
12 ms |
14364 KB |
Output is correct |
8 |
Correct |
303 ms |
14364 KB |
Output is correct |
9 |
Correct |
102 ms |
14364 KB |
Output is correct |
10 |
Correct |
315 ms |
14364 KB |
Output is correct |
11 |
Correct |
295 ms |
14364 KB |
Output is correct |
12 |
Correct |
302 ms |
14364 KB |
Output is correct |
13 |
Correct |
27 ms |
14364 KB |
Output is correct |
14 |
Correct |
83 ms |
14364 KB |
Output is correct |
15 |
Correct |
26 ms |
14364 KB |
Output is correct |
16 |
Correct |
282 ms |
14364 KB |
Output is correct |
17 |
Correct |
289 ms |
14364 KB |
Output is correct |
18 |
Correct |
114 ms |
14364 KB |
Output is correct |
19 |
Correct |
311 ms |
14364 KB |
Output is correct |
20 |
Correct |
320 ms |
14364 KB |
Output is correct |
21 |
Execution timed out |
2068 ms |
14364 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
436 KB |
Output is correct |
3 |
Correct |
3 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
608 KB |
Output is correct |
5 |
Correct |
3 ms |
608 KB |
Output is correct |
6 |
Correct |
2 ms |
608 KB |
Output is correct |
7 |
Correct |
3 ms |
608 KB |
Output is correct |
8 |
Correct |
3 ms |
628 KB |
Output is correct |
9 |
Correct |
3 ms |
628 KB |
Output is correct |
10 |
Correct |
2 ms |
628 KB |
Output is correct |
11 |
Correct |
3 ms |
628 KB |
Output is correct |
12 |
Correct |
2 ms |
628 KB |
Output is correct |
13 |
Correct |
2 ms |
628 KB |
Output is correct |
14 |
Correct |
3 ms |
696 KB |
Output is correct |
15 |
Correct |
3 ms |
696 KB |
Output is correct |
16 |
Correct |
2 ms |
696 KB |
Output is correct |
17 |
Correct |
4 ms |
936 KB |
Output is correct |
18 |
Correct |
13 ms |
1324 KB |
Output is correct |
19 |
Correct |
7 ms |
1324 KB |
Output is correct |
20 |
Correct |
3 ms |
1324 KB |
Output is correct |
21 |
Correct |
14 ms |
1408 KB |
Output is correct |
22 |
Correct |
38 ms |
1860 KB |
Output is correct |
23 |
Correct |
7 ms |
1860 KB |
Output is correct |
24 |
Correct |
54 ms |
1860 KB |
Output is correct |
25 |
Correct |
51 ms |
1860 KB |
Output is correct |
26 |
Correct |
89 ms |
1876 KB |
Output is correct |
27 |
Correct |
75 ms |
1880 KB |
Output is correct |
28 |
Correct |
48 ms |
1880 KB |
Output is correct |
29 |
Correct |
66 ms |
1880 KB |
Output is correct |
30 |
Correct |
78 ms |
1880 KB |
Output is correct |
31 |
Correct |
82 ms |
1880 KB |
Output is correct |
32 |
Correct |
75 ms |
1880 KB |
Output is correct |
33 |
Correct |
285 ms |
13040 KB |
Output is correct |
34 |
Correct |
874 ms |
13876 KB |
Output is correct |
35 |
Correct |
333 ms |
13876 KB |
Output is correct |
36 |
Correct |
893 ms |
14328 KB |
Output is correct |
37 |
Correct |
690 ms |
14328 KB |
Output is correct |
38 |
Correct |
899 ms |
14336 KB |
Output is correct |
39 |
Correct |
735 ms |
14336 KB |
Output is correct |
40 |
Correct |
850 ms |
14364 KB |
Output is correct |
41 |
Correct |
670 ms |
14364 KB |
Output is correct |
42 |
Correct |
333 ms |
14364 KB |
Output is correct |
43 |
Correct |
765 ms |
14364 KB |
Output is correct |
44 |
Correct |
391 ms |
14364 KB |
Output is correct |
45 |
Correct |
59 ms |
14364 KB |
Output is correct |
46 |
Correct |
256 ms |
14364 KB |
Output is correct |
47 |
Correct |
321 ms |
14364 KB |
Output is correct |
48 |
Correct |
289 ms |
14364 KB |
Output is correct |
49 |
Correct |
317 ms |
14364 KB |
Output is correct |
50 |
Correct |
25 ms |
14364 KB |
Output is correct |
51 |
Correct |
12 ms |
14364 KB |
Output is correct |
52 |
Correct |
303 ms |
14364 KB |
Output is correct |
53 |
Correct |
102 ms |
14364 KB |
Output is correct |
54 |
Correct |
315 ms |
14364 KB |
Output is correct |
55 |
Correct |
295 ms |
14364 KB |
Output is correct |
56 |
Correct |
302 ms |
14364 KB |
Output is correct |
57 |
Correct |
27 ms |
14364 KB |
Output is correct |
58 |
Correct |
83 ms |
14364 KB |
Output is correct |
59 |
Correct |
26 ms |
14364 KB |
Output is correct |
60 |
Correct |
282 ms |
14364 KB |
Output is correct |
61 |
Correct |
289 ms |
14364 KB |
Output is correct |
62 |
Correct |
114 ms |
14364 KB |
Output is correct |
63 |
Correct |
311 ms |
14364 KB |
Output is correct |
64 |
Correct |
320 ms |
14364 KB |
Output is correct |
65 |
Execution timed out |
2068 ms |
14364 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |