#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
ll max(ll a, signed b) {
if (a > b) return a;
return b;
}
const int N = 300 + 7;
const int INF = (int) 1e18 + 7;
int dimx, dimy, n;
struct point {
int x;
int y;
};
point v[N];
vector<int> cover[N];
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
///freopen ("input", "r", stdin);
cin >> dimx >> dimy >> n;
for (int i = 1; i <= n; i++) {
cin >> v[i].x >> v[i].y;
}
assert(dimx <= 40);
int sol = INF;
for (int a = 0; a <= dimx; a++) {
for (int b = 0; b <= dimx; b++) { /// fix north, south
for (int i = 1; i <= dimx; i++) {
cover[i].clear();
}
for (int i = 1; i <= n; i++) {
int l = max(1, v[i].x - a), r = min(dimx, v[i].x + b);
for (int j = l; j <= r; j++) {
cover[j].push_back(i);
}
}
bool ok = 1;
for (int i = 1; i <= dimx; i++) {
if (cover[i].empty()) {
ok = 0;
break;
}
}
if (!ok) {
continue;
}
/// now it's a pretty easy task
/// For each row I have some restrictions
int r1 = 0, r2 = 0, rsum = 0;
for (int i = 1; i <= dimx; i++) {
vector<int> pts;
for (auto &j : cover[i]) {
pts.push_back(v[j].y);
}
sort(pts.begin(), pts.end());
r1 = max(r1, pts[0] - 1);
r2 = max(r2, dimy - pts.back());
for (int j = 1; j < (int) pts.size(); j++) {
rsum = max(rsum, pts[j] - pts[j - 1] - 1);
}
}
rsum = max(rsum, r1 + r2);
sol = min(sol, a + b + rsum);
}
}
cout << sol << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
18 ms |
348 KB |
Output is correct |
19 |
Correct |
21 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
204 KB |
Output is correct |
21 |
Correct |
61 ms |
344 KB |
Output is correct |
22 |
Correct |
159 ms |
372 KB |
Output is correct |
23 |
Correct |
18 ms |
344 KB |
Output is correct |
24 |
Correct |
292 ms |
468 KB |
Output is correct |
25 |
Correct |
207 ms |
384 KB |
Output is correct |
26 |
Correct |
488 ms |
520 KB |
Output is correct |
27 |
Correct |
541 ms |
516 KB |
Output is correct |
28 |
Correct |
266 ms |
412 KB |
Output is correct |
29 |
Correct |
406 ms |
480 KB |
Output is correct |
30 |
Correct |
487 ms |
576 KB |
Output is correct |
31 |
Correct |
478 ms |
580 KB |
Output is correct |
32 |
Correct |
534 ms |
576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
18 ms |
348 KB |
Output is correct |
19 |
Correct |
21 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
204 KB |
Output is correct |
21 |
Correct |
61 ms |
344 KB |
Output is correct |
22 |
Correct |
159 ms |
372 KB |
Output is correct |
23 |
Correct |
18 ms |
344 KB |
Output is correct |
24 |
Correct |
292 ms |
468 KB |
Output is correct |
25 |
Correct |
207 ms |
384 KB |
Output is correct |
26 |
Correct |
488 ms |
520 KB |
Output is correct |
27 |
Correct |
541 ms |
516 KB |
Output is correct |
28 |
Correct |
266 ms |
412 KB |
Output is correct |
29 |
Correct |
406 ms |
480 KB |
Output is correct |
30 |
Correct |
487 ms |
576 KB |
Output is correct |
31 |
Correct |
478 ms |
580 KB |
Output is correct |
32 |
Correct |
534 ms |
576 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
507 ms |
444 KB |
Output is correct |
35 |
Correct |
521 ms |
492 KB |
Output is correct |
36 |
Correct |
510 ms |
508 KB |
Output is correct |
37 |
Correct |
340 ms |
580 KB |
Output is correct |
38 |
Correct |
511 ms |
432 KB |
Output is correct |
39 |
Correct |
477 ms |
612 KB |
Output is correct |
40 |
Correct |
509 ms |
512 KB |
Output is correct |
41 |
Correct |
325 ms |
564 KB |
Output is correct |
42 |
Correct |
389 ms |
480 KB |
Output is correct |
43 |
Correct |
451 ms |
524 KB |
Output is correct |
44 |
Correct |
507 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
18 ms |
348 KB |
Output is correct |
19 |
Correct |
21 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
204 KB |
Output is correct |
21 |
Correct |
61 ms |
344 KB |
Output is correct |
22 |
Correct |
159 ms |
372 KB |
Output is correct |
23 |
Correct |
18 ms |
344 KB |
Output is correct |
24 |
Correct |
292 ms |
468 KB |
Output is correct |
25 |
Correct |
207 ms |
384 KB |
Output is correct |
26 |
Correct |
488 ms |
520 KB |
Output is correct |
27 |
Correct |
541 ms |
516 KB |
Output is correct |
28 |
Correct |
266 ms |
412 KB |
Output is correct |
29 |
Correct |
406 ms |
480 KB |
Output is correct |
30 |
Correct |
487 ms |
576 KB |
Output is correct |
31 |
Correct |
478 ms |
580 KB |
Output is correct |
32 |
Correct |
534 ms |
576 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
507 ms |
444 KB |
Output is correct |
35 |
Correct |
521 ms |
492 KB |
Output is correct |
36 |
Correct |
510 ms |
508 KB |
Output is correct |
37 |
Correct |
340 ms |
580 KB |
Output is correct |
38 |
Correct |
511 ms |
432 KB |
Output is correct |
39 |
Correct |
477 ms |
612 KB |
Output is correct |
40 |
Correct |
509 ms |
512 KB |
Output is correct |
41 |
Correct |
325 ms |
564 KB |
Output is correct |
42 |
Correct |
389 ms |
480 KB |
Output is correct |
43 |
Correct |
451 ms |
524 KB |
Output is correct |
44 |
Correct |
507 ms |
632 KB |
Output is correct |
45 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 6 |
46 |
Halted |
0 ms |
0 KB |
- |