QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#485759#1819. Cleaning RobotXC220477WA 0ms3848kbC++173.0kb2024-07-21 06:02:392024-07-21 06:02:39

Judging History

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

  • [2024-07-21 06:02:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3848kb
  • [2024-07-21 06:02:39]
  • 提交

answer

#include <queue>
#include <vector>
#include <iostream>
using namespace std;

int n, m, k;
vector<vector<int>> a;
vector<vector<int>> ps;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};

bool bfs(int size, int r, int c)
{
    if (r <= 0 || c <= 0 || r > n + 1 - size || c > m + 1 - size ||
        ps[r + size - 1][c + size - 1] - ps[r][c + size - 1] -
        ps[r + size - 1][c] + ps[r + size - 1][c + size -1] > 0)
    {
        return false;
    }
    
    vector<vector<int>> visited(n + 10, vector<int>(m + 10));
    vector<vector<bool>> v(n + 10, vector<bool>(m + 10));
    queue<pair<int, int>> q;
    q.push({r, c});
    v[r][c] = true;
    
    while (!q.empty())
    {
        r = q.front().first;
        c = q.front().second;
        q.pop();
        
        visited[r][c]++;
        visited[r + size][c]--;
        visited[r][c + size]--;
        visited[r + size][c + size]++;
                
        for (int i = 0; i < 4; i++)
        {
            int newr = r + dr[i];
            int newc = c + dc[i];
            
            if (newr > 0 && newc > 0 && newr <= n + 1 - size && newc <= m + 1 - size && !v[r][c] &&
                ps[newr + size - 1][newc + size - 1] - ps[newr + size - 1][newc - 1] -
                ps[newr - 1][newc + size - 1] + ps[newr - 1][newc - 1] == 0)
            {
                q.push({newr, newc});
                v[newr][newc] = true;
            }
        }
    }
    
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            visited[i][j] += visited[i - 1][j] + visited[i][j - 1] - visited[i - 1][j - 1];
            
            if (a[i][j] == 0 && visited[i][j] <= 0) return false;
        }
    }
    
    return true;
}

int main()
{
    cin >> n >> m >> k;
    
    a = vector<vector<int>>(n + 10, vector<int>(m + 10));
    ps = vector<vector<int>>(n + 10, vector<int>(m + 10));
    
    for (int i = 0; i < k; i++)
    {
        int r, c;
        cin >> r >> c;
        
        a[r][c] = 1;
    }
    
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            ps[i][j] = ps[i - 1][j] + ps[i][j - 1] - ps[i - 1][j - 1] + a[i][j];
        }
    }
    
    int startr = 0, startc = 0;
    bool done = false;
    
    for (int i = 1; i <= n && !done; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (a[i][j] == 0)
            {
                startr = i;
                startc = j;
                done = true;
                break;
            }
        }
    }

    if (!bfs(1, startr, startc))
    {
        cout << -1 << endl;
        return 0;
    }
    
    int l = 1;
    int r = n;
    
    if (m < n) r = m;
    
    while (l < r)
    {
        int mid = (l + r + 1) / 2;
        bool valid = bfs(mid, startr, startc);
        
        if (valid) l = mid;
        else r = mid - 1;
    }
    
    cout << l << endl;
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

10 7 1
8 3

output:

-1

result:

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