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>;
bool check (V<bitset<41>> &f, int r, int c) {
for (int i = 1; i <= r; ++i) for (int j = 1; j <= c; ++j)
if (f[i][j] == 0) return false;
return true;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int r, c, n;
cin >> r >> c >> n;
V<int> x(n), y(n);
for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];
int ans = r + c - 2;
V<bitset<41>> b(41);
for (int i = 0; i < n; ++i) b[x[i]][y[i]] = 1;
for (int u = 0; u < r; ++u) for (int d = 0; d < r; ++d) {
V<bitset<41>> f = b;
for (int i = 0; i < u; ++i) {
for (int j = 1; j < r; ++j) f[j] |= f[j + 1];
}
for (int i = 0; i < d; ++i) {
for (int j = r; j > 1; --j) f[j] |= f[j - 1];
}
for (int l = 0; l < c; ++l) for (int ri = 0; ri < c; ++ri) {
V<bitset<41>> foo = f;
for (int i = 0; i < l; ++i) for (int j = 1; j <= r; ++j) foo[j] |= foo[j] << 1;
for (int i = 0; i < ri; ++i) for (int j = 1; j <= r; ++j) foo[j] |= foo[j] >> 1;
if (check(foo, r, c) && u + d + l + ri < ans) {
dbg(u, d, l, ri);
ans = min(ans, u + d + l + ri);
}
}
}
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... |