📑 Qualification Round 2018
Task 1. Saving The Universe Again
📓 Variant 1. Python Only
def damage(SC):
K,D,N=1,0,len(SC)
if 'C' not in SC:
D==N
for i in range(N):
if SC[i]=='S':
D+=K
else:
K*=2
return D
def reduce_damage(SC,D):
C,N=0,len(SC)
if damage(SC)>D:
while 'CS' in SC:
idx=SC[::-1].index('SC')
SC=SC[:N-idx-2]+'SC'+SC[N-idx:]
C+=1
if damage(SC)<=D:
break
return C,damage(SC)-D
T=int(input())
for t in range(T):
[D,SC]=input().split()
D=int(D)
# print(D,damage(SC))
# print(reduce_damage(SC,D))
C,DIFF=reduce_damage(SC,D)
if DIFF>0:
print('Case #{}: IMPOSSIBLE'.format(t+1))
else:
print('Case #{}: {}'.format(t+1,C))
📓 Variant 1. SageMath Interactive
Task 2. Trouble Sort
📓 Variant 1. Python Only
def trouble_sort(L,N):
LE,LO=[],[]
for i in range(N):
(LO,LE)[i%2==0].append(L[i])
LE=sorted(LE)
LO=sorted(LO)
L=sorted(L)
for i in range(N):
if i%2==0:
el=LE[i//2]
else:
el=LO[i//2]
if el!=L[i]:
break
if N-1!=i:
return str(i)
else:
return 'OK'
T=int(input())
for t in range(T):
N=int(input())
L=list(map(int,input().split()))
ANS=trouble_sort(L,N)
print('Case #{}: {}'.format(t+1,ANS))
📓 Variant 1. SageMath Interactive
Task 3. Go, Gopher!
📓 Process Simulation
📓 Variant 1. Python Only
#10pts, RE for the last ✓
def go_gopher(a):
k=a//3+1
l=k//3
ra=[3*i+2 for i in list(range(l))]
if k-1>ra[-1]:
ra+=[k-1]
c=1000
go_ra=[ra[j%len(ra)] for j in range(c)]
for i in go_ra:
out_xy='%d 2'%i
print(out_xy,flush=True)
in_xy=input()
if in_xy=='0 0':
break
elif in_xy=='-1 -1':
exit()
T=int(input())
for i in range(T):
A=int(input())
go_gopher(A)
📓 Variant 2. Python Only
#10pts, 20pts ✓ ✓
def go_gopher(a):
k=a//3+1
l=k//3
ra=[3*i+2 for i in list(range(l))]
if k-1>ra[-1]:
ra+=[k-1]
c=1000
go_ra=[ra[j%len(ra)] for j in range(c)]
for i in go_ra:
x,y=[i-1,i,i+1],[1,2,3]
xy=[' '.join([str(el) for el in [xy1,xy2]])
for xy1 in x for xy2 in y]
flag=False
while xy!=[]:
out_xy='%d 2'%i
print(out_xy,flush=True)
in_xy=input()
if in_xy in xy:
xy.remove(in_xy)
elif in_xy=='0 0':
flag=True
break
elif in_xy=='-1 -1':
exit()
# print(xy)
if flag==True:
break
T=int(input())
for i in range(T):
A=int(input())
go_gopher(A)
📓 Variant 2. SageMath Interactive
Task 4. Cubic UFO
📓 Variant 1. Python Only
📓 Variant 1. SageMath Interactive