QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#483059#1819. Cleaning Robotpatboi008WA 14ms3872kbC++172.9kb2024-07-18 10:25:382024-07-18 10:25:39

Judging History

你现在查看的是最新测评结果

  • [2024-07-18 10:25:39]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:3872kb
  • [2024-07-18 10:25:38]
  • 提交

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;
            int obsCount = obsPrefix[x2][y2] - obsPrefix[x1 - 1][y2] - obsPrefix[x2][y1 - 1] + obsPrefix[x1 - 1][y1 - 1];
            if (obsCount == 0) {
                applySetter(cleaned, x1, y1, x2, y2);
            }
        }
    }
    return checkCoverage(obs, cleaned, n, m);
}


void visAll(vector<vector<bool>> vis, vector<vector<int>>& obs, int i, int j, int n, int m){
  if(i <= 0 || j <= 0 || i > n || j > m || obs[i][j] == 1 || vis[i][j]){
    return;
  }
  vis[i][j] = true;
  visAll(vis, obs, i+1, j, n, m);
  visAll(vis, obs, i, j+1, n, m);
  return;
}

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;
    }
    if(k == n*m){
      cout << "-1" << endl;
      return 0;
    }
  vector<vector<bool>> visited(n + 2, vector<bool>(m + 2, false));
  visAll(visited, obstructed, 1, 1, n, m);
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      if(!visited[i][j] && obstructed[i][j] == 0){
        cout << "-1" << endl;
        return 0;
      }
    }
  }
    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 = 0, 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: 14ms
memory: 3872kb

input:

10 7 1
8 3

output:

-1

result:

wrong answer expected '2', found '-1'