#ifdef DeBuG
#include "debug.h"
#else
#include <bits/stdc++.h>
#define dbg(...)
#endif
using namespace std;
#define fi first
#define se second
#define pb push_back
#define sz(v) (int)(v).size()
#define all(v) begin(v),end(v)
#define rep(i,a,b) for (int i=(a);i<(b);++i)
using ll = long long; template <class T> using V = vector<T>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
int R, C, N;
struct Rect {
int x1, y1, x2, y2;
Rect () {}
void up () { x1 = max(x1 - 1, 1); }
void dw () { x2 = min(x2 + 1, R); }
void le () { y1 = max(y1 - 1, 1); }
void ri () { y2 = min(y2 + 1, C); }
void up (int k) { while (k--) up(); }
void dw (int k) { while (k--) dw(); }
void le (int k) { while (k--) le(); }
void ri (int k) { while (k--) ri(); }
};
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> R >> C >> N;
V<Rect> rect(N);
for (int i = 0; i < N; ++i) {
int x, y; cin >> x >> y;
rect[i].x1 = rect[i].x2 = x;
rect[i].y1 = rect[i].y2 = y;
}
int ans = R + C - 2;
for (int u = 0; u < R; ++u) for (int d = 0; d < R; ++d) {
V<Rect> a = rect;
for (int i = 0; i < N; ++i) { a[i].up(u); a[i].dw(d); }
int n1 = 0, n2 = 0, n3 = 0;
V<int> pts[R + 1];
for (int i = 1; i <= R; ++i) {
for (int j = 0; j < N; ++j) if (a[j].x1 <= i && i <= a[j].x2)
pts[i].pb(a[j].y1);
sort(all(pts[i]));
}
for (int i = 1; i <= R; ++i) {
if (pts[i].empty()) { n1 = 1e9, n2 = 1e9; break; }
n1 = max(n1, pts[i][0] - 1);
n2 = max(n2, C - pts[i].back());
}
for (int i = 1; i <= R; ++i) {
for (int j = 0; j + 1 < sz(pts[i]); ++j) {
int x = pts[i][j] + n2, y = pts[i][j + 1] - n1;
if (x + 1 < y) n3 = max(n3, y - x - 1);
}
}
dbg(u, d, n1, n2, n3);
ans = min(ans, u + d + n1 + n2 + n3);
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
452 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
452 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
10 ms |
348 KB |
Output is correct |
19 |
Correct |
15 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
29 ms |
468 KB |
Output is correct |
22 |
Correct |
73 ms |
348 KB |
Output is correct |
23 |
Correct |
18 ms |
344 KB |
Output is correct |
24 |
Correct |
143 ms |
484 KB |
Output is correct |
25 |
Correct |
101 ms |
488 KB |
Output is correct |
26 |
Correct |
296 ms |
528 KB |
Output is correct |
27 |
Correct |
280 ms |
348 KB |
Output is correct |
28 |
Correct |
138 ms |
344 KB |
Output is correct |
29 |
Correct |
240 ms |
508 KB |
Output is correct |
30 |
Correct |
284 ms |
512 KB |
Output is correct |
31 |
Correct |
288 ms |
348 KB |
Output is correct |
32 |
Correct |
289 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
452 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
10 ms |
348 KB |
Output is correct |
19 |
Correct |
15 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
29 ms |
468 KB |
Output is correct |
22 |
Correct |
73 ms |
348 KB |
Output is correct |
23 |
Correct |
18 ms |
344 KB |
Output is correct |
24 |
Correct |
143 ms |
484 KB |
Output is correct |
25 |
Correct |
101 ms |
488 KB |
Output is correct |
26 |
Correct |
296 ms |
528 KB |
Output is correct |
27 |
Correct |
280 ms |
348 KB |
Output is correct |
28 |
Correct |
138 ms |
344 KB |
Output is correct |
29 |
Correct |
240 ms |
508 KB |
Output is correct |
30 |
Correct |
284 ms |
512 KB |
Output is correct |
31 |
Correct |
288 ms |
348 KB |
Output is correct |
32 |
Correct |
289 ms |
512 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
319 ms |
528 KB |
Output is correct |
35 |
Correct |
303 ms |
772 KB |
Output is correct |
36 |
Correct |
324 ms |
344 KB |
Output is correct |
37 |
Correct |
198 ms |
344 KB |
Output is correct |
38 |
Correct |
336 ms |
348 KB |
Output is correct |
39 |
Correct |
297 ms |
348 KB |
Output is correct |
40 |
Correct |
319 ms |
344 KB |
Output is correct |
41 |
Correct |
143 ms |
520 KB |
Output is correct |
42 |
Correct |
181 ms |
344 KB |
Output is correct |
43 |
Correct |
270 ms |
512 KB |
Output is correct |
44 |
Correct |
318 ms |
516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
131 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
131 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
452 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
10 ms |
348 KB |
Output is correct |
19 |
Correct |
15 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
29 ms |
468 KB |
Output is correct |
22 |
Correct |
73 ms |
348 KB |
Output is correct |
23 |
Correct |
18 ms |
344 KB |
Output is correct |
24 |
Correct |
143 ms |
484 KB |
Output is correct |
25 |
Correct |
101 ms |
488 KB |
Output is correct |
26 |
Correct |
296 ms |
528 KB |
Output is correct |
27 |
Correct |
280 ms |
348 KB |
Output is correct |
28 |
Correct |
138 ms |
344 KB |
Output is correct |
29 |
Correct |
240 ms |
508 KB |
Output is correct |
30 |
Correct |
284 ms |
512 KB |
Output is correct |
31 |
Correct |
288 ms |
348 KB |
Output is correct |
32 |
Correct |
289 ms |
512 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
319 ms |
528 KB |
Output is correct |
35 |
Correct |
303 ms |
772 KB |
Output is correct |
36 |
Correct |
324 ms |
344 KB |
Output is correct |
37 |
Correct |
198 ms |
344 KB |
Output is correct |
38 |
Correct |
336 ms |
348 KB |
Output is correct |
39 |
Correct |
297 ms |
348 KB |
Output is correct |
40 |
Correct |
319 ms |
344 KB |
Output is correct |
41 |
Correct |
143 ms |
520 KB |
Output is correct |
42 |
Correct |
181 ms |
344 KB |
Output is correct |
43 |
Correct |
270 ms |
512 KB |
Output is correct |
44 |
Correct |
318 ms |
516 KB |
Output is correct |
45 |
Runtime error |
131 ms |
262144 KB |
Execution killed with signal 9 |
46 |
Halted |
0 ms |
0 KB |
- |