QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#500951 | #1819. Cleaning Robot | askeww | WA | 0ms | 3584kb | C++17 | 3.9kb | 2024-08-02 05:39:57 | 2024-08-02 05:39:58 |
Judging History
answer
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct node {
int x, y, size;
};
int n, m, k, x, y, size_l, size_r, ans = 0;
vector<pair<int, int>> obstructions;
vector<vector<bool>> obstructed_map;
queue<node> q;
bool check(int size) {
vector<vector<int>> obstructed_prefix = vector<vector<int>>(n - size + 1, vector<int>(m - size + 1, 0));
for (int i = 0; i < k; i++) {
int x_1 = max(0, obstructions[i].first - size + 1);
int y_1 = max(0, obstructions[i].second - size + 1);
int x_2 = obstructions[i].first + 1;
int y_2 = obstructions[i].second + 1;
obstructed_prefix[x_1][y_1] += 1;
if (x_2 < obstructed_prefix.size()) obstructed_prefix[x_2][y_1] -= 1;
if (y_2 < obstructed_prefix[0].size()) obstructed_prefix[x_1][y_2] -= 1;
if (x_2 < obstructed_prefix.size() && y_2 < obstructed_prefix[0].size()) obstructed_prefix[x_2][y_2] += 1;
}
for (int i = 0; i + size <= n; i++) {
int total = 0;
for (int j = 0; j + size <= m; j++) {
total += obstructed_prefix[i][j];
obstructed_prefix[i][j] = (i > 0) ? obstructed_prefix[i - 1][j] : 0;
obstructed_prefix[i][j] += total;
}
}
vector<vector<bool>> visited = vector<vector<bool>>(n - size + 1, vector<bool>(m - size + 1, false));
for (int i = 0; i < visited.size(); i++) {
for (int j = 0; j < visited[0].size(); j++) {
if (!obstructed_prefix[i][j]) {
q = queue<node>();
q.push({i, j, size});
while (!q.empty()) {
node cur = q.front();
q.pop();
if (cur.x < 0 || cur.y < 0 || cur.x >= visited.size() || cur.y >= visited[0].size()) continue;
if (obstructed_prefix[cur.x][cur.y] || visited[cur.x][cur.y]) continue;
visited[cur.x][cur.y] = true;
q.push({cur.x - 1, cur.y, size});
q.push({cur.x + 1, cur.y, size});
q.push({cur.x, cur.y - 1, size});
q.push({cur.x, cur.y + 1, size});
}
vector<vector<int>> visited_prefixes = vector<vector<int>>(n, vector<int>(m, 0));
for (int a = 0; a < visited.size(); a++) {
for (int b = 0; b < visited[0].size(); b++) {
if (visited[a][b]) {
int x_1 = a;
int y_1 = b;
int x_2 = a + size;
int y_2 = b + size;
visited_prefixes[x_1][y_1] = visited_prefixes[x_1][y_1] + 1;
if (x_2 < n) visited_prefixes[x_2][y_1] = visited_prefixes[x_2][y_1] - 1;
if (y_2 < m) visited_prefixes[x_1][y_2] = visited_prefixes[x_1][y_2] - 1;
if (x_2 < n && y_2 < m) visited_prefixes[x_2][y_2] = visited_prefixes[x_2][y_2] + 1;
}
}
}
for (int a = 0; a < n; a++) {
int total = 0;
for (int b = 0; b < m; b++) {
total += visited_prefixes[a][b];
visited_prefixes[a][b] = (a > 0) ? visited_prefixes[a - 1][b] : 0;
visited_prefixes[a][b] += total;
if (!obstructed_map[a][b] && visited_prefixes[a][b] == 0) {
return false;
}
}
}
return true;
}
}
}
return true;
}
int main() {
freopen("sample.in", "r", stdin);
cin >> n >> m >> k;
obstructions = vector<pair<int, int>>(k);
obstructed_map = vector<vector<bool>>(n, vector<bool>(m, 0));
for (int i = 0; i < k; i++) {
cin >> obstructions[i].first >> obstructions[i].second;
obstructions[i].first--; obstructions[i].second--;
obstructed_map[obstructions[i].first][obstructions[i].second] = true;
}
size_l = 1;
size_r = min(n, m);
while (size_l < size_r) {
int size_m = (size_l + size_r) / 2;
if (check(size_m)) {
size_l = size_m + 1;
ans = max(ans, size_m);
} else {
size_r = size_m;
}
}
cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3584kb
input:
10 7 1 8 3
output:
0
result:
wrong answer expected '2', found '0'