This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define ff first
#define ss second
int A[50];
pii P[2500];
int R, C, N;
bool f(int a, int b, int c, int d) {
vector<pii> v[50];
fill(A, A + C + 1, 0);
for (int i = 0; i < N; ++i) {
int x1 = P[i].ff - a, x2 = P[i].ff + b, y1 = P[i].ss - c, y2 = P[i].ss + d;
x1 = max(1, x1);
x2 = min(R, x2);
y1 = max(1, y1);
y2 = min(C, y2);
v[x1].emplace_back(y1, y2);
v[x2 + 1].emplace_back(-y1, y2);
}
int cnt = 0;
for (int i = 1; i <= R; ++i) {
for (auto j : v[i]) {
if (j.ff > 0) {
for (int k = j.ff; k <= j.ss; ++k) {
if (!A[k]) cnt++;
A[k]++;
}
}
else {
for (int k = -j.ff; k <= j.ss; ++k) {
A[k]--;
if (!A[k]) cnt--;
}
}
}
if (cnt != C) return 0;
}
return 1;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> R >> C >> N;
for (int i = 0; i < N; ++i) {
int x, y; cin >> x >> y;
P[i] = {x, y};
}
int ans = R + C;
for (int i = 0; i <= R; ++i) {
for (int j = 0; j <= R - i; ++j) {
for (int k = 0; k <= C; ++k) {
for (int l = 0; l <= C - k; ++l) {
if (f(i, j, k, l) && ans > i + j + k + l) ans = i + j + k + l;
}
}
}
}
cout << ans;
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... |