QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#485754#1819. Cleaning RobotXC220477RE 0ms0kbC++172.8kb2024-07-21 05:31:342024-07-21 05:31:35

Judging History

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

  • [2024-07-21 05:31:35]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-07-21 05:31:34]
  • 提交

answer

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

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

bool bfs(int size)
{
    queue<pair<int, int>> q;
        
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (a[i][j] == 0 && q.empty())
            {
                if (j > m - size || i > n - size ||
                    ps[i + size - 1][j + size - 1] - ps[i + size - 1][j - 1] -
                    ps[i - 1][j + size - 1] + ps[i - 1][j - 1] > 0)
                {
                    return false;
                }
                
                q.push({i, j});
            }
            visited[i][j] = 0;
        }
    }
    
    while (!q.empty())
    {
        int r = q.front().first;
        int 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 && visited[newr][newc] <= 0 &&
                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});
            }
        }
    }
    
    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, vector<int>(m));
    ps = vector<vector<int>>(n, vector<int>(m));
    visited = vector<vector<int>>(n, vector<int>(m));
    
    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];
        }
    }
    
    if (!bfs(1))
    {
        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);
        
        if (valid) l = mid;
        else r = mid - 1;
    }
    
    cout << l << endl;
    
    return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

10 7 1
8 3

output:


result: