QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#483032 | #1819. Cleaning Robot | patboi008 | WA | 1ms | 3560kb | C++17 | 2.4kb | 2024-07-18 10:04:39 | 2024-07-18 10:04:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void applySetter(vector<vector<int>>& cleaned, int x1, int y1, int x2, int y2) {
cleaned[x1][y1]++;
cleaned[x1][y2 + 1]--;
cleaned[x2 + 1][y1]--;
cleaned[x2 + 1][y2 + 1]++;
}
bool checkCoverage(vector<vector<int>>& obs, vector<vector<int>>& cleaned, int n, int m) {
vector<vector<int>> result(n + 1, vector<int>(m + 1, 0));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
result[i][j] = cleaned[i][j] + result[i - 1][j] + result[i][j - 1] - result[i - 1][j - 1];
if (obs[i][j] == 0 && result[i][j] == 0) {
return false;
}
}
}
return true;
}
bool canCoverAll(vector<vector<int>>& obs, vector<vector<int>>& obsPrefix, int size, int n, int m) {
vector<vector<int>> cleaned(n + 2, vector<int>(m + 2, 0));
for (int i = 1; i <= n - size + 1; i++) {
for (int j = 1; j <= m - size + 1; j++) {
int x1 = i, y1 = j;
int x2 = i + size - 1, y2 = j + size - 1;
cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
int obsCount = obsPrefix[x2][y2] - obsPrefix[x1 - 1][y2] - obsPrefix[x2][y1 - 1] + obsPrefix[x1 - 1][y1 - 1];
cout << obsCount << " " << obsPrefix[x2][y2]<< endl;
if (obsCount == 0) {
cout << "happened" << endl;
applySetter(cleaned, x1, y1, x2, y2);
}
}
}
return checkCoverage(obs, cleaned, n, m);
}
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<vector<int>> obstructed(n + 1, vector<int>(m + 1, 0));
for (int i = 0; i < k; i++) {
int a, b;
cin >> a >> b;
obstructed[a][b] = 1;
}
vector<vector<int>> obsPrefix(n + 1, vector<int>(m + 1, 0));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
obsPrefix[i][j] = obstructed[i][j] + obsPrefix[i - 1][j] + obsPrefix[i][j - 1] - obsPrefix[i - 1][j - 1];
}
}
int left = 1, right = min(n, m), ans = 0;
while (left <= right) {
int mid = (left + right) / 2;
if (canCoverAll(obstructed, obsPrefix, mid, n, m)) {
ans = mid;
left = mid + 1;
} else {
right = mid - 1;
}
}
if (ans == 0) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3560kb
input:
10 7 1 8 3
output:
1 1 4 4 0 0 happened 1 2 4 5 0 0 happened 1 3 4 6 0 0 happened 1 4 4 7 0 0 happened 2 1 5 4 0 0 happened 2 2 5 5 0 0 happened 2 3 5 6 0 0 happened 2 4 5 7 0 0 happened 3 1 6 4 0 0 happened 3 2 6 5 0 0 happened 3 3 6 6 0 0 happened 3 4 6 7 0 0 happened 4 1 7 4 0 0 happened 4 2 7 5 0 0 happened 4 3 7 ...
result:
wrong answer expected '2', found '1'