Farewell Round A 2023. Task 2
Python Only
def update(i,start,end,radius,condition,answer):
while (i < N):
if X[i]-start > radius: break
else: end=X[i]
i+=1
if end!=condition:
answer+=[end]
start=end
else:
answer=[]
return i,start,end,answer
T=int(input())
for t in range(T):
[M,R,N]=list(map(int,input().split()))
X=list(map(int,input().split()))
i,start,end,answer=0,0,-1,[]
i,start,end,answer=update(i,start,end,R,-1,answer)
while ((i < N) and (answer!=[]) and (end+R < M)):
i,start,end,answer=update(i,start,end,2*R,start,answer)
if M-end > R: answer=[]
if answer!=[]:
print('Case #{}: {}'.format((t+1),len(answer)))
else:
print('Case #{}: IMPOSSIBLE'.format(t+1))
xxxxxxxxxx
def illumination_optimization(
T=selector([1,2,3],default=1,label='$\\mathbb{T}$'),
MRN=input_box('10 3 3\n10 2 3\n10 2 4',type=str,
label='$\\mathbb{MRN}$',width=10,height=3),
XL=input_box('2 7 9\n2 7 9\n2 3 7 9',type=str,
label='$\\mathbb{XL}$',width=10,height=3)):
[M,R,N]=list(map(int,(str(MRN).split('\n')[T-1]).split()))
X=list(map(int,(str(XL).split('\n')[T-1]).split()))
pretty_print([T,M,R,N,X])
def update(i,start,end,radius,condition,answer,N=N,X=X):
while (i < N):
if X[i]-start > radius: break
else: end=X[i]
i+=1
if end!=condition:
answer+=[end]
start=end
else:
answer=[]
return i,start,end,answer
i,start,end,answer=0,0,-1,[]
i,start,end,answer=update(i,start,end,R,-1,answer)
while ((i < N) and (answer!=[]) and (end+R < M)):
i,start,end,answer=update(i,start,end,2*R,start,answer)
if M-end > R: answer=[]
if answer!=[]:
pretty_print('Case #{}: {}'.format((T),len(answer)))
else:
pretty_print('Case #{}: IMPOSSIBLE'.format(T))