📑 Farewell Round A 2023
Task 1. Colliding Encoding
📓 Variant 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))
📓 Variant 2. Python Only
T=int(input())
letters='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for t in range(T):
digits=input().replace(' ','')
ld=dict(zip(list(letters),list(digits)))
N=int(input())
numbers=set()
words=set()
answer='NO'
for i in range(N):
w=input()
words.update([w])
n=''.join([ld[s] for s in w])
numbers.update([n])
if len(numbers) < len(words):
answer='YES'
print('Case #{}: {}'.format((t+1),answer))
📓 Variant 1. SageMath Interactive
Task 2. Illumination Optimization
📓 Variant 1. 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())
#T=1
for t in range(T):
[M,R,N]=list(map(int,input().split()))
# [M,R,N]=list(map(int,'12 2 6'.split()))
X=list(map(int,input().split()))
# X=list(map(int,'0 3 4 7 8 9'.split()))
i,start,end,answer=0,0,-1,[]
i,start,end,answer=update(i,start,end,R,-1,answer)
# print(i,start,end,answer)
while ((i < N) and (answer!=[]) and (end+R < M)):
i,start,end,answer=update(i,start,end,2*R,start,answer)
# print(i,start,end,answer)
if M-end > R: answer=[]
if answer!=[]:
print('Case #{}: {}'.format((t+1),len(answer)))
else:
print('Case #{}: IMPOSSIBLE'.format(t+1))
📓 Variant 1. SageMath Interactive
Task 3. Rainbow Sort
📓 Variant 1. Python Only
T=int(input())
for t in range(T):
N=int(input())
cards=input().split()
cards_set=set()
result=[]
for i in range(N):
if cards[i] not in cards_set:
cards_set.update([cards[i]])
result.append(cards[i])
elif result[-1]!=cards[i]:
result='IMPOSSIBLE'
break
# print(i,result)
if result!='IMPOSSIBLE': result=' '.join(result)
print('Case #{}: {}'.format((t+1),result))
📓 Variant 1. SageMath Interactive
Task 4. ASCII Art
📓 Variant 1. Python Only
letters='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def count26down(number):
diff1,i,j=number,1,0
while number>0:
diff1=number; k1=i
number-=i*26; i+=1
while diff1>0:
diff2=diff1; k2=j
diff1-=k1; j+=1
return k2
T=int(input())
for t in range(T):
N=int(input())
L=letters[count26down(N)]
print('Case #{}: {}'.format((t+1),L))
📓 Variant 1. SageMath Interactive
Task 5. Untie
📓 Variant 1. Python Only
T=int(input())
for t in range(T):
C=input()
if len(set(C))==1:
count=len(C)//2+len(C)%2
else:
while C[0]==C[-1]:
C=C[1:]+C[0]
count=C.count('PP')+C.count('SS')+C.count('RR')
print('Case #{}: {}'.format((t+1),count))
📓 Variant 1. SageMath Interactive