Saturday, April 29, 2023

📑 Farewell Round A 2023 Task 2 Illumination Optimization

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))
        


📑 Farewell Round A 2023 Task 1 Colliding Encoding

Farewell Round A 2023. Task 1

Python Only

T=int(input())
letters='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for t in range(T):
    D=input().replace(' ','')
    N=int(input())
    numbers=set()
    words=set()
    for i in range(N):
        w=input()
        words.update([w])
        n=''.join([D[letters.find(s)] for s in w])
        numbers.update([n])
    if len(numbers) < len(words):
        print('Case #{}: YES'.format(t+1))
    else:
        print('Case #{}: NO'.format(t+1))