QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#486828#1819. Cleaning RoboteTL 7ms10668kbPython31.8kb2024-07-22 05:17:142024-07-22 05:17:14

Judging History

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

  • [2024-07-22 05:17:14]
  • 评测
  • 测评结果:TL
  • 用时:7ms
  • 内存:10668kb
  • [2024-07-22 05:17:14]
  • 提交

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: 100
Accepted
time: 7ms
memory: 10668kb

input:

10 7 1
8 3

output:

2

result:

ok answer is '2'

Test #2:

score: -100
Time 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:


result: