QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#773225#1819. Cleaning RobotBroderWA 0ms3608kbC++173.3kb2024-11-23 06:28:052024-11-23 06:28:05

Judging History

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

  • [2024-11-23 06:28:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3608kb
  • [2024-11-23 06:28:05]
  • 提交

answer

#include <bits/stdc++.h>
#include <iostream>
#include <queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define sz(x) (int)(x).size()

typedef long long ll;

int n, m, k;
int cnt;
vector<vector<bool>> obst;
vector<vector<int>> closestObstRow, closestObstCol;

bool works(int s) {
    vector<vector<bool>> validTL(n, vector<bool>(m, false));
    pair<int, int> st = {-1, -1};
    int v = 0;
    rep(i, n-s+1) {
        int cnt = 0;
        rep(j, m) {
            if (closestObstCol[i][j] < s) cnt++;
            if (j >= s and closestObstCol[i][j-s] < s) cnt--;
            if (j >= s-1 and cnt==0) v++, validTL[i][j-s+1] = true, st = {i, j-s+1};
        }
    }
    int newV=0;
    queue<pair<int, int>> q;
    vector<vector<bool>> visited(n, vector<bool>(m, false));
    if (st != make_pair(-1, -1)) newV++, q.push(st);
    vector<pair<int, int>> adjs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    while(sz(q)) {
        pair<int, int> curr = q.front(); q.pop();
        for (pair<int, int> adj : adjs) {
            int newR = curr.first + adj.first;
            int newC = curr.second + adj.second;
            if (newR >= 0 and newR < n-s+1 and newC >= 0 and newC < m-s+1) {
                if (!visited[newR][newC] and validTL[newR][newC]) newV++, visited[newR][newC] = true, q.push({newR, newC});
            }
        }
    }
    if (newV!=v) return false;
    vector<vector<bool>> covered(n, vector<bool>(m, false));
    int o = 0;
    rep(i, n) {
        int curr = 0;
        rep(j, m) {
            if (visited[i][j]) curr = s;
            if (curr > 0) o+=(!covered[i][j]), covered[i][j] = true;
            curr--;
        }
    }

    rep(j, m) {
        int curr = 0;
        rep(i, n) {
            if (covered[i][j]) curr = s;
            if (curr > 0) o+=(!covered[i][j]), covered[i][j] = true;
            curr--;
        }
    }

    // rep(i, n) {
    //     rep(j, m) cout << covered[i][j] << ' ';
    //     cout << endl;
    // }

    return o==cnt;
}

int main() {
    cin >> n >> m >> k;
    obst = vector<vector<bool>>(n, vector<bool>(m, false));
    closestObstRow = vector<vector<int>>(n, vector<int>(m, 1e9));
    closestObstCol = vector<vector<int>>(n, vector<int>(m, 1e9));
    cnt = n*m;
    rep(i, k) {
        int a, b; cin >> a >> b;
        obst[a-1][b-1] = true;
        closestObstRow[a-1][b-1] = 0;
        closestObstCol[a-1][b-1] = 0;
        cnt--;
    }
    rep(ii, n) {
        rep(jj, m) { int i = n-1-ii, j = m-1-jj;
            if (j != m-1) {
                if (closestObstRow[i][j+1]!=1e9) closestObstRow[i][j] = min(closestObstRow[i][j], closestObstRow[i][j+1]+1);
            }
            if (i != n-1) {
                if (closestObstCol[i+1][j]!=1e9) closestObstCol[i][j] = min(closestObstCol[i][j], closestObstCol[i+1][j]+1);
            }
        }
    }
    // rep(i, n) {
    //     rep(j, m) cout << closestObstCol[i][j] << ' ';
    //     cout << endl;
    // }

    int lo = 1, hi = min(n, m), ans = -1;

    while (lo <= hi) {
        int mid = (lo+hi)/2;
        if (works(mid)) {
            ans = mid;
            lo = mid+1;
        }
        else hi = mid-1;
        // cout << mid << endl;
    }

    cout << ans << endl;
}   

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3608kb

input:

10 7 1
8 3

output:

-1

result:

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