QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#500931#1819. Cleaning RobotwholetmecookCompile Error//C++143.1kb2024-08-02 04:00:462024-08-02 04:00:46

Judging History

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

  • [2024-08-02 04:00:46]
  • 评测
  • [2024-08-02 04:00:46]
  • 提交

answer

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

const int N = 5000005;

int r, c, b;
vector<int> ps[N], d[N], g[N];
vector<bool> v[N];
int ec;

pair<int, int> q[N];
int qs, qe;


bool check(int sz) {
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            bool isBlock = true;
            if (i + sz > r || j + sz > c) isBlock = true;
            else isBlock = ps[i + sz][j + sz] - ps[i][j + sz] - ps[i + sz][j] + ps[i][j];
            g[i][j] = isBlock;
        }
    }

    for (int i = 0; i <= r; i++) {
        for (int j = 0; j <= c; j++) {
            d[i][j] = 0;
        }
    }

    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            if (!g[i][j]) {
                d[i][j]++;
                d[i + sz][j]--;
                d[i][j + sz]--;
                d[i + sz][j + sz]++;
            }
        }
    }

    for (int i = 0; i <= r; i++) {
        for (int j = 0; j <= c; j++) {
            if (i < r) d[i + 1][j] += d[i][j];
            if (j < c) d[i][j + 1] += d[i][j];
            if (i < r && j < c) d[i + 1][j + 1] -= d[i][j];
        }
    }

    int nec = 0;
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            nec += !!d[i][j];
        }
    }
    if (nec != ec) return false;

    int eCells = 0;
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            eCells += !g[i][j];
        }
    }

    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            if (g[i][j]) continue;
            bfs(i, j);
            return qe == eCells;
        }
    }

    return false;
}

void bfs(int sx, int sy) {
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            v[i][j] = false;
        }
    }
    v[sx][sy] = true;
    qs = qe = 0;
    q[qe++] = {sx, sy};

    const pair<int, int> D[4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

    while (qs < qe) {
        auto [cx, cy] = q[qs++];
        for (auto [dx, dy] : D) {
            int nx = cx + dx, ny = cy + dy;
            if (nx < 0 || nx >= r || ny < 0 || ny >= c || v[nx][ny] || g[nx][ny]) continue;
            v[nx][ny] = true;
            q[qe++] = {nx, ny};
        }
    }
}

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> r >> c >> b;
    for (int i = 0; i <= r; i++) {
        ps[i].resize(c + 1);
        d[i].resize(c + 1);
        g[i].resize(c + 1);
        v[i].resize(c + 1);
    }

    ec = r * c - b;
    while (b--) {
        int x, y;
        cin >> x >> y;
        ps[x][y] = 1;
    }

    for (int i = 0; i <= r; i++) {
        for (int j = 0; j <= c; j++) {
            if (i < r) ps[i + 1][j] += ps[i][j];
            if (j < c) ps[i][j + 1] += ps[i][j];
            if (i < r && j < c) ps[i + 1][j + 1] -= ps[i][j];
        }
    }

    int low = 0, high = min(r, c);
    while (low < high) {
        int mid = (low + high + 1) / 2;
        bool result = check(mid);
        if (result) low = mid;
        else high = mid - 1;
    }

    if (low == 0) cout << "-1\n";
    else cout << low << '\n';
}

Details

answer.code: In function ‘bool check(int)’:
answer.code:68:13: error: ‘bfs’ was not declared in this scope; did you mean ‘ffs’?
   68 |             bfs(i, j);
      |             ^~~
      |             ffs
answer.code: In function ‘void bfs(int, int)’:
answer.code:89:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   89 |         auto [cx, cy] = q[qs++];
      |              ^
answer.code:90:19: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   90 |         for (auto [dx, dy] : D) {
      |                   ^