QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#500952 | #1819. Cleaning Robot | askeww | WA | 2ms | 9104kb | C++17 | 3.8kb | 2024-08-02 05:40:28 | 2024-08-02 05:40:28 |
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() {
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3524kb
input:
10 7 1 8 3
output:
2
result:
ok answer is '2'
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 9104kb
input:
2236 2236 2214 28 1255 389 2175 730 592 1360 977 1225 752 1403 1798 1518 1381 147 745 659 249 951 1475 1826 1951 691 1033 81 1458 1487 1946 2106 1395 1995 629 470 891 1902 822 2210 2001 441 2130 1198 1539 2027 1101 215 1149 205 420 379 2104 308 1225 859 109 1417 2078 1764 376 1772 5 335 1113 917 118...
output:
2235
result:
wrong answer expected '1', found '2235'