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 solve (int L, const V<int> &x) {
bitset<41> b;
for (int i : x) b[i] = 1;
int ret = L;
for (int i = 0; i < L; ++i) {
bitset<41> f = b;
for (int j = 0; j < i; ++j) f |= (f << 1);
if (!f[L]) continue;
int need = 0;
for (int j = L; j > 0; --j) {
if (f[j]) continue;
int k = j;
while (k - 1 > 0 && !f[k - 1]) --k;
need = max(need, j - k + 1);
j = k;
}
dbg(i, need); cerr << "f = " << f << "\n";
need += i;
ret = min(ret, need);
}
return ret;
}
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 = solve(c, x) + solve(r, y);
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... |