QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#485755#1819. Cleaning RobotXC220477TL 1ms3688kbC++172.8kb2024-07-21 05:32:222024-07-21 05:32:22

Judging History

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

  • [2024-07-21 05:32:22]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3688kb
  • [2024-07-21 05:32:22]
  • 提交

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 + 10, vector<int>(m + 10));
    ps = vector<vector<int>>(n + 10, vector<int>(m + 10));
    visited = 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];
        }
    }
    
    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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3688kb

input:

10 7 1
8 3

output:

2

result:

ok answer is '2'

Test #2:

score: -100
Time Limit Exceeded

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: