QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#486779#1819. Cleaning RobotXC230595TL 0ms3580kbC++172.1kb2024-07-22 01:40:552024-07-22 01:40:55

Judging History

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

  • [2024-07-22 01:40:55]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3580kb
  • [2024-07-22 01:40:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

vector<vector<int>> dis = {{1, 0, -1, 0}, {0, 1, 0, -1}};
void dfs(int n, int m, vector<vector<bool>> &visited, vector<vector<int>> &ps, vector<vector<int>> &clean, int s, int i, int j) {
    visited[i][j] = true;
    clean[i][j]++; clean[i+s][j]--; clean[i][j+s]--; clean[i+s][j+s]++;
    for (int d = 0; d < 4; d++) {
        int i2 = i+dis[0][d], j2 = j+dis[1][d];
        if (1 <= i2 && i2 <= n-s+1 && 1 <= j2 && j2 <= m-s+1 && !visited[i2][j2] && ps[i2+s-1][j2+s-1]-ps[i2+s-1][j2-1]-ps[i2-1][j2+s-1]+ps[i2-1][j2-1] == 0) {
            dfs(n, m, visited, ps, clean, s, i2, j2);
        }
    }
}

bool works(int n, int m, vector<vector<bool>> &carpet, int s) {
    vector<vector<int>> ps(n+1, vector<int>(m+1, 0)), clean(n+2, vector<int>(m+2, 0));
    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] + carpet[i][j];
        }
    }

    for (int i = 1; i <= n-s+1; i++) {
        for (int j = 1; j <= m-s+1; j++) {
            if (ps[i+s-1][j+s-1]-ps[i+s-1][j-1]-ps[i-1][j+s-1]+ps[i-1][j-1] == 0) {
                vector<vector<bool>> visited(n+1, vector<bool>(m+1, false));
                dfs(n, m, visited, ps, clean, s, i, j);
                break;
            }
        }
    }

    vector<vector<int>> cps(n+1, vector<int>(m+1, 0));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cps[i][j] = cps[i-1][j] + cps[i][j-1] - cps[i-1][j-1] + clean[i][j];
            if (!carpet[i][j] && cps[i][j] == 0) return false;
        }
    }
    return true;
}

signed main() {
    // input
    int n, m, k; cin >> n >> m >> k;
    vector<vector<bool>> carpet(n+1, vector<bool>(m+1));
    for (int i = 0; i < k; i++) {
        int x, y; cin >> x >> y;
        carpet[x][y] = true;
    }

    // binary search
    int l = 0, r = min(n, m);
    while (l < r) {
        int s = (l+r+1)/2;
        if (works(n, m, carpet, s)) {
            l = s;
        } else {
            r = s-1;
        }
    }
    cout << (l == 0 ? -1 : l) << endl;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3580kb

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: