📑 Qualification Round 2019
Task 1. Foregone Solution
📓 Variant 1. Python Only
T = int(input())
try:
for i in range(T):
S = input()
A = ''
for j in range(1,len(S)+1):
if int(S[-j]) == 4:
A = '1' + A
else:
A = S[-j] + A
B = str(int(S) - int(A))
print('Case #{}: '.format(i+1), A, B)
except StopIteration: pass
📓 Variant 1. SageMath Interactive
Task 2. You Can Go Your Own Way
📓 Variant 1. Python Only
T = int(input())
try:
for i in range(T):
L = int(input())
S = input()
W = S.replace('S','L').replace('E','S').replace('L','E')
print('Case #{}: '.format(i+1), W)
except StopIteration: pass
📓 Variant 1. SageMath Interactive
Task 3. Cryptopangrams
📓 Variant 1. Python Only
def eacd(a,b):
if b==0:
return a
else:
return eacd(b,a%b)
def replace_zero(num_list,num_len,crypto_list):
for i in range(num_len):
if (crypto_list[i]==0) and (crypto_list[i+1]!=0):
crypto_list[i]=num_list[i]//crypto_list[i+1]
if (crypto_list[i]!=0) and (crypto_list[i+1]==0):
crypto_list[i+1]=num_list[i]//crypto_list[i]
return crypto_list
def crypto_string(num_list,num_len):
crypto_list=(num_len+1)*[0]
for i in range(num_len-1):
if num_list[i]!=num_list[i+1]:
crypto_list[i+1]=eacd(num_list[i],num_list[i+1])
while 0 in crypto_list:
crypto_list=replace_zero(num_list,num_len,crypto_list)
prime_set=list(set(crypto_list))
prime_set.sort()
letter_set=list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
dl=dict(zip(prime_set,letter_set))
crypto_str=''
for i in range(num_len+1):
crypto_str+=dl[crypto_list[i]]
return crypto_str
T=int(input())
for t in range(T):
max_num,num_len=map(int,input().split())
num_list=list(map(int,input().split()))
answer=crypto_string(num_list,num_len)
print('Case #{}: {}'.format(t+1,answer))
📓 Variant 1. SageMath Interactive
Task 4. Dat Bae
📓 Process Simulation
📓 Variant 1. Python Only
#14pts, RE for the last ✓
def dat_bae(N,B):
K=N-B
Nb=(N-1).bit_length()
outcols=[format(i,'0%db'%(Nb)) for i in range(N)]
incols=N*['']
for j in range(Nb):
outrow=''.join(
[outcols[i][Nb-j-1] for i in range(N)])
print(outrow,flush=True)
inrow=input()
for i in range(K):
incols[i]=inrow[i]+incols[i]
answer=[i for i in range(N)
if outcols[i] not in incols]
print(' '.join(map(str,answer)),flush=True)
ans=input()
if ans!='1':
exit()
T=int(input())
for i in range(T):
N,B,F=map(int,input().split())
dat_bae(N,B)
📓 Variant 1. SageMath Interactive
📓 Variant 2. Python Only
#14pts,20pts ✓ ✓
def dat_bae_cols(N,B,F):
Nb=(N-1).bit_length()
outcols=[format(i,'0%db'%(Nb)) for i in range(N)]
incols=N*['']
for j in range(Nb):
if j>F-1:
break
outrow=''.join([outcols[i][Nb-j-1] for i in range(N)])
print(outrow,flush=True)
inrow=input()
for i in range(N-B):
incols[i]=inrow[i]+incols[i]
return outcols,incols
def dat_bae_fans(N,B,F,outcols,incols):
answer,boolean_answer,L=[],False,16
K,la=(N-B)//L+1,len(answer)
for k in range(K+1):
curr_incols=incols[L*k-la:L*(k+1)-la]
curr_outcols=outcols[L*k:L*(k+1)]
for i in range(len(curr_outcols)):
if curr_outcols[i][-F:] not in curr_incols:
answer.append(L*k+i)
la=len(answer)
if la==B:
booleban_answer=True
break
if boolean_answer:
break
return answer
T=int(input())
for i in range(T):
N,B,F=map(int,input().split())
outcols,incols=dat_bae_cols(N,B,F)
answer=dat_bae_fans(N,B,F,outcols,incols)
print(' '.join(map(str,answer)),flush=True)
ans=input()
if ans!='1':
exit()
📓 Variant 2. SageMath Interactive