QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#389841 | #1819. Cleaning Robot | black_moonrise# | ML | 87ms | 628652kb | C++14 | 1.8kb | 2024-04-14 20:17:37 | 2024-04-14 20:17:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e6 + 5;
typedef long long ll;
int n, m, k;
vector <int> mp[MAXN], cnt[MAXN];
vector <bool> blk[MAXN], vis[MAXN];
void dfs(int x, int y) {
vis[x][y] = false;
if (vis[x + 1][y]) dfs(x + 1, y);
if (vis[x][y + 1]) dfs(x, y + 1);
if (vis[x - 1][y]) dfs(x - 1, y);
if (vis[x][y - 1]) dfs(x, y - 1);
}
bool check(int mid) {
for (int i = 0; i <= n + 1; i++)
for (int j = 0; j <= m + 1; j++)
cnt[i][j] = vis[i][j] = 0;
int x = 1, y = 1;
for (int i = mid; i <= n; i++)
for (int j = mid; j <= m; j++)
if (mp[i][j] - mp[i - mid][j] - mp[i][j - mid] + mp[i - mid][j - mid] == mid * mid) {
cnt[i][j] += 1;
cnt[i - mid][j] -= 1;
cnt[i][j - mid] -= 1;
cnt[i - mid][j - mid] += 1;
vis[i][j] = true;
x = i, y = j;
}
for (int i = n; i >= 1; i--)
for (int j = m; j >= 1; j--) {
cnt[i][j] += cnt[i + 1][j] + cnt[i][j + 1] - cnt[i + 1][j + 1];
if (cnt[i][j] == 0 && !blk[i][j]) return false;
}
dfs(x, y);
for (int i = mid; i <= n; i++)
for (int j = mid; j <= m; j++)
if (vis[i][j]) return false;
return true;
}
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i <= n + 1; i++) {
mp[i].resize(m + 2);
cnt[i].resize(m + 2);
vis[i].resize(m + 2);
blk[i].resize(m + 2);
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
mp[i][j] = 1;
for (int i = 1; i <= k; i++) {
int x, y; scanf("%d%d", &x, &y);
mp[x][y] = 0; blk[x][y] = true;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
mp[i][j] += mp[i - 1][j] + mp[i][j - 1] - mp[i - 1][j - 1];
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) cout << -1 << endl;
else cout << l << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 87ms
memory: 628652kb
input:
10 7 1 8 3
output:
2
result:
ok answer is '2'
Test #2:
score: -100
Memory 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:
1