This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |