QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#524829#1819. Cleaning RobottutamizWA 1ms5648kbC++142.8kb2024-08-20 08:56:402024-08-20 08:56:40

Judging History

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

  • [2024-08-20 08:56:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5648kb
  • [2024-08-20 08:56:40]
  • 提交

answer

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

int n, m, K;
vector<vector<int> > sumob;
vector<vector<int> > sumpos;

int count_ob(int i1, int j1, int i2, int j2) {
	return sumob[i2][j2] - sumob[i1 - 1][j2] - sumob[i2][j1 - 1] + sumob[i1 - 1][j1 - 1];
}
int count_pos(int i1, int j1, int i2, int j2) {
	return sumpos[i2][j2] - sumpos[i1 - 1][j2] - sumpos[i2][j1 - 1] + sumpos[i1 - 1][j1 - 1];
}

int id(int i, int j) {
	return (i - 1) * m + j;
}

int fa[10'000'005], sz[10'000'006];
int get_fa(int u) {
	if (u == fa[u]) {
		return u;
	}
	return fa[u] = get_fa(fa[u]);
}
void merge(int u, int v) {
	int fu = get_fa(u);
	int fv = get_fa(v);
	if (fu != fv) {
		if (sz[fu] > sz[fv]) {
			swap(fu, fv);
		}
		fa[fu] = fv;
		sz[fv] += sz[fu];
	}
}

bool check(int mid) {
	sumpos = vector<vector<int> >(n + 2, vector<int> (m + 2));
	for (int i = 1; i + mid - 1 <= n; ++i) {
		for (int j = 1; j + mid - 1 <= m; ++j) {
			if (count_ob(i, j, i + mid - 1, j + mid - 1)) {
				sumpos[i][j] = 0;
			} else {
				sumpos[i][j] = 1;
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			sumpos[i][j] += sumpos[i][j - 1];
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			sumpos[i][j] += sumpos[i - 1][j];
		}
	}
	
	for (int i = 1; i <= n * m; ++i) {
		fa[i] = i;
		sz[i] = 1;
	}
	
	for (int i = 1; i + mid - 1 <= n; ++i) {
		for (int j = 1; j + mid - 1 <= m; ++j) {
			if (count_pos(i, j, i, j)) {
				if (i + 1 <= n && count_pos(i + 1, j, i + 1, j)) {
					merge(id(i, j), id(i + 1, j));
				}
				if (j + 1 <= m && count_pos(i, j + 1, i, j + 1)) {
					merge(id(i, j), id(i, j + 1));
				}
			}
		}
	}
	
	int cnt = 0;
	for (int i = 1; i + mid - 1 <= n; ++i) {
		for (int j = 1; j + mid - 1 <= m; ++j) {
			if (count_pos(i, j, i, j) && get_fa(id(i, j)) == id(i, j)) {
				cnt++;
			}
		}
	}
	return cnt == 1;
}

int main() {
  // freopen("meet.in", "r", stdin);
  //freopen("meet.out", "w", stdout);
  // cin.tie(0)->sync_with_stdio(0);
  // cout.tie(0);
  int id, T = 1;
  // std::cin >> id >> T;
  while (T--) {
    cin >> n >> m >> K;
    sumob = vector<vector<int> >(n + 2, vector<int> (m + 2));
    for (int i = 1; i <= K; ++i) {
      int x, y;
      cin >> x >> y;
      sumob[x][y] = 1;
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        sumob[i][j] += sumob[i][j - 1];
      }
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        sumob[i][j] += sumob[i - 1][j];
      }
    }
    
    int l = 0, r = min(n, m);
    while (l < r) {
      int mid = (l + r + 1) / 2;
      if (check(mid)) {
        l = mid;
      } else {
        r = mid - 1;
      }
    }
    
    if (l == 0) {
      l = -1;
    }
    
    cout << l << endl;
  } 
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5648kb

input:

10 7 1
8 3

output:

7

result:

wrong answer expected '2', found '7'