QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#486826 | #1819. Cleaning Robot | e | WA | 5ms | 10592kb | Python3 | 1.9kb | 2024-07-22 05:03:13 | 2024-07-22 05:03:13 |
Judging History
answer
from collections import deque
n, m, k = [int(_) for _ in input().split()]
xys = [[0] * (m + 1) for i in range(n + 1)]
for i in range(k):
x, y = [int(a) for a in input().split()]
xys[x][y] = 1
for i in range(1, n + 1):
for j in range(1, m + 1):
xys[i][j] += xys[i - 1][j] + xys[i][j - 1] - xys[i - 1][j - 1]
left, right = 1, min(n, m)
def possible(s):
flag = False
for i in range(1, n - s + 2):
for j in range(1, m - s + 2):
if xys[i + s - 1][j + s - 1] - xys[i + s - 1][j - 1] - xys[i - 1][j + s - 1] + xys[i - 1][j - 1] == 0:
dq = deque([[i, j]])
seen = {(i, j)}
flag = True
break
if flag:
break
if flag:
clean = [[0] * (m + 2) for _ in range(n + 2)]
while dq:
x, y = dq.popleft()
clean[x][y] += 1
clean[x + s][y] += -1
clean[x][y + s] += -1
clean[x + s][y + s] += 1
for nx, ny in [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]]:
if 0 < nx <= n - s + 1 and 0 < ny <= m - s + 1 and (nx, ny) not in seen and xys[nx + s - 1][ny + s - 1] - xys[nx + s - 1][ny - 1] - xys[nx - 1][ny + s - 1] + xys[nx - 1][ny - 1] == 0:
dq.append([nx, ny])
seen.add((nx, ny))
count = 0
for i in range(1, n + 1):
for j in range(1, m + 1):
clean[i][j] += clean[i - 1][j] + clean[i][j- 1] - clean[i - 1][j - 1]
if clean[i][j] > 0:
count += 1
return count == n * m - k
else:
return False
while left + 1 < right:
mid = (left + right) // 2
if possible(mid):
left = mid
else:
right = mid
print(right if possible(right) else left if possible(left) else -1)
詳細信息
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 10592kb
input:
10 7 1 8 3
output:
-1
result:
wrong answer expected '2', found '-1'