#include <bits/stdc++.h>
using namespace std;
#define NAME "DISPERSAL"
#define int long long
#define pii pair < int , int >
#define fi first
#define se second
const int N = 1e6 + 3;
int r, c, n;
pii tree[N];
namespace Subtask1 {
int wind[N], huong[5];
int maxWind, cnt, res;
map < pii, int > mp;
bool checkSub1() {
return (r <= 4 && c <= 4);
}
void init() {
mp.clear();
cnt = n;
// for (int i = 0; i <= 3; i++) last[i] = 0;
for (int i = 1; i <= n; i++) {
mp[tree[i]] = 1;
}
}
bool inside(int x, int y) {
return ((x >= 1 && y >= 1) && (x <= r && y <= c));
}
void update() {
for (int i = 1; i <= maxWind; i++) {
for (pair < pii, int > w: mp) {
if (w.se > i) continue;
int x = w.fi.fi, y = w.fi.se;
if (wind[i] == 0) {
y--;
}
else if (wind[i] == 1) {
x--;
}
else if (wind[i] == 2) {
y++;
}
else if (wind[i] == 3) {
x++;
}
if (!inside(x, y)) continue;
if (mp[{x, y}] == 0) {
mp[{x, y}] = i + 1;
cnt++;
}
}
if (cnt == r * c) {
res = min(res, i);
return;
}
}
}
void Try(int id) {
if (id > maxWind) {
init();
update();
// for (int i = 1; i <= maxWind; i++) {
// cout << wind[i] << " ";
// }
// cout << res << " " << '\n';
// if (wind[1] % 2 == 0 && wind[3] % 2 == 0)
// cout << last[0] << " " << last[1] << '\n';
return;
}
else {
for (int i = 0; i <= 3; i++) {
if (huong[i % 2] >= max(r, c))
continue;
wind[id] = i;
huong[i % 2]++;
Try(id + 1);
huong[i % 2]--;
}
}
}
void solve() {
// checkSub1();
init();
for (int i = 0; i <= 3; i++) {
huong[i] = 0;
}
for (int i = 0; i <= maxWind; i++) {
wind[i] = 0;
}
maxWind = r + c - 1;
res = maxWind;
// wind[1] = 3;
// wind[2] = 3;
// wind[3] = 0;
// wind[4] = 0;
// wind[5] = 3;
// update();
Try(1);
cout << res;
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen(NAME".inp","r",stdin);
// freopen(NAME".out","w",stdout);
cin >> r >> c >> n;
for (int i = 1; i <= n; i++) {
int x, y;
cin >> x >> y;
tree[i] = {x, y};
}
Subtask1::solve();
}
| # | 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... |