QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#486788#1819. Cleaning RobotXC230595WA 0ms3620kbC++172.3kb2024-07-22 02:11:352024-07-22 02:11:35

Judging History

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

  • [2024-07-22 02:11:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3620kb
  • [2024-07-22 02:11:35]
  • 提交

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<int>> &ps, vector<vector<int>> &clean, int s, int s_i, int s_j) {
    vector<vector<bool>> visited(n+1, vector<bool>(m+1, false));
    stack<pair<int, int>> stack;
    stack.emplace(s_i, s_j);

    while (!stack.empty()) {
        int i = stack.top().first, j = stack.top().second; stack.pop();
        clean[i][j]++; clean[i+s][j]--; clean[i][j+s]--; clean[i+s][j+s]++;
        visited[i][j] = true;

        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) {
                stack.emplace(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) {
                dfs(n, m, 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;
        cout << l << " " << r << " " << s << endl;
        if (works(n, m, carpet, s)) {
            l = s;
        } else {
            r = s-1;
        }
    }
    cout << (l == 0 ? -1 : l) << endl;
}

詳細信息

Test #1:

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

input:

10 7 1
8 3

output:

0 7 4
0 3 2
2 3 3
2

result:

wrong answer expected '2', found '0'