QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#486836#1819. Cleaning RoboteCompile Error//C++172.3kb2024-07-22 05:51:282024-07-22 05:51:29

Judging History

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

  • [2024-07-22 05:51:29]
  • 评测
  • [2024-07-22 05:51:28]
  • 提交

answer

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

int n, m, k;
vector<vector<int>> prefixsum;

bool works(int s){
    bool visited[n + 1][m + 1];
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= m; j++){
            visited[i][j] = false;
        }
    }
    queue<pair<int, int>> q;
    bool found = false;
    for (int i = 1; i <= n - s + 1; i++){
        for (int j = 1; j <= m - s + 1; j++){
            if (prefixsum[i + s - 1][j + s - 1] - prefixsum[i + s - 1][j - 1] - prefixsum[i - 1][j + s - 1] + prefixsum[i - 1][j - 1] == 0){
				q.push({i, j});
                visited[i][j] = true;
                found = true;
                break;
            }
        }
        if (found){break;}
    }
    if (!found){return false;}
	vector<vector<int>> clean (n + 2, vector<int>(m + 1, 0));
	while (!q.empty()) {
		int x = q.front().first, y = q.front().second;
		q.pop();
		clean[x][y]++;
		clean[x + s][y]--;
		clean[x][y + s]--;
		clean[x + s][y + s]++;
		int dx[4] = {0, 0, 1, -1};
		int dy[4] = {1, -1, 0, 0};
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i], ny = y + dy[i];
			if (nx > 0 && nx <= n - s + 1 && ny > 0 && ny <= m - s + 1 && !visited[nx][ny] && prefixsum[nx + s - 1] [ny + s- 1] - prefixsum[nx + s - 1][nx - 1] - prefixsum[ny - 1][ny + s - 1] + prefixsum[nx - 1][ny - 1] == 0) {
				q.push({nx, ny});
				visited[nx][ny] = true;
			}
		}
	}
	int count = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			clean[i][j] += clean[i - 1][j] + clean[i][j - 1] - cleanpi - 1][j - 1];
			if (clean[i][j] > 0) count++;
		}
	}
	return count == n * m - k;
}

int main(){
    cin >> n >> m >> k;
    prefixsum.resize(n + 1, vector<int>(m + 1, 0));
    for (int i = 0; i < k; i++){
        int x, y;
        cin >> x >> y;
        prefixsum[x][y] = 1;
    }
    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= m; j++){
            prefixsum[i][j] += prefixsum[i - 1][j] + prefixsum[i][j - 1] - prefixsum[i - 1][j - 1];
        }
    }
    int left = 0;
    int right = min(n, m);
    while (left < right){
        int mid = (left + right)/2;
        if (works(mid)){
            left = mid;
        }
        else{
            right = mid - 1;
        }
    }
    if (works(left)){
        cout << left;
    }
    else{
        cout << -1;
    }
}

詳細信息

answer.code: In function ‘bool works(int)’:
answer.code:50:76: error: ‘cleanpi’ was not declared in this scope; did you mean ‘clean’?
   50 |                         clean[i][j] += clean[i - 1][j] + clean[i][j - 1] - cleanpi - 1][j - 1];
      |                                                                            ^~~~~~~
      |                                                                            clean