#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; u + 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
856 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
856 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 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 |
5 ms |
464 KB |
Output is correct |
19 |
Correct |
6 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
25 ms |
472 KB |
Output is correct |
22 |
Correct |
53 ms |
344 KB |
Output is correct |
23 |
Correct |
7 ms |
344 KB |
Output is correct |
24 |
Correct |
87 ms |
500 KB |
Output is correct |
25 |
Correct |
56 ms |
348 KB |
Output is correct |
26 |
Correct |
149 ms |
484 KB |
Output is correct |
27 |
Correct |
153 ms |
512 KB |
Output is correct |
28 |
Correct |
78 ms |
508 KB |
Output is correct |
29 |
Correct |
133 ms |
504 KB |
Output is correct |
30 |
Correct |
152 ms |
496 KB |
Output is correct |
31 |
Correct |
153 ms |
516 KB |
Output is correct |
32 |
Correct |
159 ms |
520 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
856 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 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 |
5 ms |
464 KB |
Output is correct |
19 |
Correct |
6 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
25 ms |
472 KB |
Output is correct |
22 |
Correct |
53 ms |
344 KB |
Output is correct |
23 |
Correct |
7 ms |
344 KB |
Output is correct |
24 |
Correct |
87 ms |
500 KB |
Output is correct |
25 |
Correct |
56 ms |
348 KB |
Output is correct |
26 |
Correct |
149 ms |
484 KB |
Output is correct |
27 |
Correct |
153 ms |
512 KB |
Output is correct |
28 |
Correct |
78 ms |
508 KB |
Output is correct |
29 |
Correct |
133 ms |
504 KB |
Output is correct |
30 |
Correct |
152 ms |
496 KB |
Output is correct |
31 |
Correct |
153 ms |
516 KB |
Output is correct |
32 |
Correct |
159 ms |
520 KB |
Output is correct |
33 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
146 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
146 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
856 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 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 |
5 ms |
464 KB |
Output is correct |
19 |
Correct |
6 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
25 ms |
472 KB |
Output is correct |
22 |
Correct |
53 ms |
344 KB |
Output is correct |
23 |
Correct |
7 ms |
344 KB |
Output is correct |
24 |
Correct |
87 ms |
500 KB |
Output is correct |
25 |
Correct |
56 ms |
348 KB |
Output is correct |
26 |
Correct |
149 ms |
484 KB |
Output is correct |
27 |
Correct |
153 ms |
512 KB |
Output is correct |
28 |
Correct |
78 ms |
508 KB |
Output is correct |
29 |
Correct |
133 ms |
504 KB |
Output is correct |
30 |
Correct |
152 ms |
496 KB |
Output is correct |
31 |
Correct |
153 ms |
516 KB |
Output is correct |
32 |
Correct |
159 ms |
520 KB |
Output is correct |
33 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |