QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#486838 | #1819. Cleaning Robot | e | WA | 0ms | 3748kb | C++17 | 2.3kb | 2024-07-22 05:52:52 | 2024-07-22 05:52:52 |
Judging History
answer
#include <iostream>
#include <queue>
using namespace std;
int n, m, k;
vector<vector<int>> prefixsum;
bool works(int s){
bool visited[n + 1][m + 1];
for (int i = 0; i <= n; i++){
for (int j = 0; j <= m; j++){
visited[i][j] = false;
}
}
queue<pair<int, int>> q;
bool found = false;
for (int i = 1; i <= n - s + 1; i++){
for (int j = 1; j <= m - s + 1; j++){
if (prefixsum[i + s - 1][j + s - 1] - prefixsum[i + s - 1][j - 1] - prefixsum[i - 1][j + s - 1] + prefixsum[i - 1][j - 1] == 0){
q.push({i, j});
visited[i][j] = true;
found = true;
break;
}
}
if (found){break;}
}
if (!found){return false;}
vector<vector<int>> clean (n + 2, vector<int>(m + 1, 0));
while (!q.empty()) {
int x = q.front().first, y = q.front().second;
q.pop();
clean[x][y]++;
clean[x + s][y]--;
clean[x][y + s]--;
clean[x + s][y + s]++;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
for (int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if (nx > 0 && nx <= n - s + 1 && ny > 0 && ny <= m - s + 1 && !visited[nx][ny] && prefixsum[nx + s - 1] [ny + s- 1] - prefixsum[nx + s - 1][nx - 1] - prefixsum[ny - 1][ny + s - 1] + prefixsum[nx - 1][ny - 1] == 0) {
q.push({nx, ny});
visited[nx][ny] = true;
}
}
}
int count = 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] > 0) count++;
}
}
return count == n * m - k;
}
int main(){
cin >> n >> m >> k;
prefixsum.resize(n + 1, vector<int>(m + 1, 0));
for (int i = 0; i < k; i++){
int x, y;
cin >> x >> y;
prefixsum[x][y] = 1;
}
for (int i = 1; i <= n; i++){
for (int j = 0; j <= m; j++){
prefixsum[i][j] += prefixsum[i - 1][j] + prefixsum[i][j - 1] - prefixsum[i - 1][j - 1];
}
}
int left = 1;
int right = min(n, m);
while (left < right){
int mid = (left + right)/2;
if (works(mid)){
left = mid;
}
else{
right = mid - 1;
}
}
if (works(left)){
cout << left;
}
else{
cout << -1;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3748kb
input:
10 7 1 8 3
output:
-1
result:
wrong answer expected '2', found '-1'