QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#483677 | #1819. Cleaning Robot | Elvinoo | TL | 0ms | 3632kb | C++17 | 2.3kb | 2024-07-19 01:49:46 | 2024-07-19 01:49:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector<vector<int>> grid;
vector<vector<int>> maze;
bool bfs(int x, int y) {
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int vis = 1;
vector<vector<bool>> visited(n + 1, vector<bool>(m + 1, false));
queue<pair<int, int>> q;
q.push({x, y});
visited[x][y] = true;
while (!q.empty()) {
pair<int, int> curr = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int nx = curr.first + dx[i];
int ny = curr.second + dy[i];
if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && !visited[nx][ny] && maze[nx][ny] == 0) {
visited[nx][ny] = true;
q.push({nx, ny});
vis++;
}
}
}
return vis == (n*m) - k;
}
bool valid(int x) {
vector<vector<int>> clean(n + 5, vector<int>(m + 5, 0));
for (int i = x; i <= n; i++) {
for (int j = x; j <= m; j++) {
int cnt = grid[i][j] - grid[i - x][j] - grid[i][j - x] + grid[i - x][j - x];
if (cnt == 0) {
clean[i - x + 1][j - x + 1]++;
clean[i - x + 1][j + 1]--;
clean[i + 1][j - x + 1]--;
clean[i + 1][j + 1]++;
}
}
}
int vis = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
clean[i][j] += clean[i - 1][j] + clean[i][j - 1] - clean[i - 1][j - 1];
if (clean[i][j]) vis++;
}
}
return vis == (n*m) - k;
}
int main() {
cin >> n >> m >> k;
grid.resize(n + 5, vector<int>(m + 5, 0));
maze.resize(n + 5, vector<int>(m + 5, 0));
for (int i = 0; i < k; i++) {
int x, y;
cin >> x >> y;
grid[x][y] = 1;
maze[x][y] = 1;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
grid[i][j] += grid[i - 1][j] + grid[i][j - 1] - grid[i - 1][j - 1];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (maze[i][j] == 0) {
if (!bfs(i, j)) {
cout << -1 << "\n";
return 0;
}
else {
break;
}
}
}
}
int l = 1, r = min(n,m);
while (l <= r) {
int mid = (l + r) / 2;
if (valid(mid)) {
l = mid + 1;
}
else {
r = mid - 1;
}
}
cout << r << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
input:
10 7 1 8 3
output:
2
result:
ok answer is '2'
Test #2:
score: -100
Time Limit Exceeded
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...