QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#485751#1819. Cleaning RobotXC220477RE 1ms5668kbC++172.6kb2024-07-21 05:22:042024-07-21 05:22:04

Judging History

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

  • [2024-07-21 05:22:04]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5668kb
  • [2024-07-21 05:22:04]
  • 提交

answer

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

int n, m, k;
int a[501][501];
int ps[501][501];
int visited[501][501];
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;
    
    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: 100
Accepted
time: 1ms
memory: 5668kb

input:

10 7 1
8 3

output:

2

result:

ok answer is '2'

Test #2:

score: -100
Runtime Error

input:

2236 2236 2214
28 1255
389 2175
730 592
1360 977
1225 752
1403 1798
1518 1381
147 745
659 249
951 1475
1826 1951
691 1033
81 1458
1487 1946
2106 1395
1995 629
470 891
1902 822
2210 2001
441 2130
1198 1539
2027 1101
215 1149
205 420
379 2104
308 1225
859 109
1417 2078
1764 376
1772 5
335 1113
917 118...

output:


result: