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;
typedef long long ll;
void openFiles() {
#ifdef KEK
assert(freopen("input.txt", "r", stdin));
assert(freopen("output.txt", "w", stdout));
#endif
}
void IOoptimize() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
struct Action {
int time;
int l, r;
int type;
int id;
};
bool operator< (const Action &a1, const Action &a2) {
if (a1.time == a2.time)
return a1.id < a2.id;
return a1.time < a2.time;
}
const int MAXN = 300;
const int MAX = 40;
int x[MAXN], y[MAXN];
int f[MAX];
int main() {
openFiles();
IOoptimize();
int r, c;
cin >> r >> c;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
x[i]--;
y[i]--;
}
int ans = INT_MAX;
int cnt[4];
for (cnt[0] = 0; cnt[0] <= MAX; cnt[0]++)
for (cnt[1] = 0; cnt[1] <= MAX; cnt[1]++)
for (cnt[2] = 0; cnt[2] <= MAX; cnt[2]++)
for (cnt[3] = 0; cnt[3] <= MAX; cnt[3]++) {
int new_ans = cnt[0] + cnt[1] + cnt[2] + cnt[3];
if (ans <= new_ans)
continue;
memset(f, 0, sizeof(f));
vector<Action> v;
for (int i = 0; i < n; i++) {
Action act;
act.id = i;
act.time = max(y[i] - cnt[1], 0);
act.l = max(x[i] - cnt[0], 0);
act.r = min(x[i] + cnt[2], r - 1);
act.type = 1;
v.push_back(act);
act.time = min(y[i] + cnt[3] + 1, c);
act.type = -1;
v.push_back(act);
}
sort(v.begin(), v.end());
int last = 0;
int sq = 0;
for (auto act : v) {
//cout << act.time << " " << act.l << " " << act.r << " " << act.type << "\n";
int active_count = 0;
for (int i = 0; i < r; i++)
if (f[i])
active_count++;
sq += active_count * (act.time - last);
last = act.time;
for (int i = act.l; i <= act.r; i++)
f[i] += act.type;
}
//cout << sq << "\n";
//cout << "--/--\n";
if (sq == r * c)
ans = new_ans;
}
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... |