注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
一个月后OA
We are given:
- memory blocks:where.
- You can increase one block by(only once and only if).
- The MEX (minimum excluded value) of the array is the smallest non-negative integer not present in it.
We must find all possible MEX values after performing 0 or 1 operation.
solution :
def findValidSizes(memoryBlocks):
n = len(memoryBlocks)
freq = [0] * (n + 1) for val in memoryBlocks:
freq[val] += 1
# Find initial MEX
mex = 0
while freq[mex] > 0:
mex +=ange(0, mex + 2))
else:
# we can't fill missing lower numbers
result = list(range(0, mex + 1))
return result
if name == "main": n = int(input().strip()) memoryBlocks = [int(input().strip()) for _ in range(n)] ans = findValidSizes(memoryBlocks) for x in ans: print(x) |