📑 Practice Session 2018

Task 1. Number Guessing

📓 Variant 1. Python Only


T = int(input())
try:
    for i in range(T):
        S = input()
        S = [int(s) for s in S.split()]
        A, B = S[0]+1, S[1]
        N = int(input())
        for j in range(N):
            Q = A + (B - A) // 2
            print(Q, flush=True)
            Answer = input()
            if Answer == 'WRONG_ANSWER':
                raise StopIteration
            elif Answer == 'CORRECT':
                break
            elif Answer == 'TOO_SMALL':
                if (B - A) // 2 == 0:
                    A = A + 1
                else:
                    A = A + (B - A) // 2
            elif Answer == 'TOO_BIG':
                if (B - A )// 2 == 0:
                    B = B - 1
                else:                
                    B = B - (B - A) // 2              
except StopIteration: pass

📓 Variant 1. SageMath Interactive


Task 2. Senate Evacuation

📓 Variant 1. Python Only


T = int(input())
A = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
for i in range(T):
    N = int(input())
    S = input()
    S = [int(s) for s in S.split()]
    path = ''
    while sum(S) > 0:   
        max_value = max(S)
        max_index = [i for i in range(N) if S[i] == max_value]   
        if sum(S) == 3:
            S[max_index[0]] -= 1
            path += A[max_index[0]] + ' '
        elif len(max_index) == 1:
            S[max_index[0]] -= 2
            path += 2*A[max_index[0]] + ' '
        elif len(max_index) > 1:
            S[max_index[0]] -= 1
            S[max_index[1]] -= 1        
            path += A[max_index[0]] + A[max_index[1]] + ' '    
    print('Case #{}: '.format(i+1), path)

📓 Variant 1. SageMath Interactive


Task 3. Steed 2: Cruise Control

📓 Variant 1. Python Only


# input the test number
T = int(input())
for i in range(T): 
    S1 = input()
    S1 = [int(s) for s in S1.split()]
    D, N = S1[0], S1[1]
    # the variable "cruise control speed"
    ccs_max = 0   
    for j in range(N):  
        S2 = input()
        S2 = [int(s) for s in S2.split()]
        K, S = S2[0], S2[1]
        # find the average speed to not pass this horse
        current = D / (D - K) * S
        # update the optimal "cruise control" speed
        if (ccs_max == 0 or current < ccs_max):
            ccs_max = current 
    print('Case #{}: '.format(i+1), ccs_max)

📓 Variant 1. SageMath Interactive


Task 4. Bathroom Stalls

📓 Process Simulation


📓 Variant 1. Python Only


✓ ✓ MLE
def ceil(n):
    return -int(-n//1)
def floor(n):
    return int(n//1)
T=int(input())
for t in range(T): 
    N,K=map(int,input().split())
    C={i:0 for i in range(N+1)}
    C[N]=1; S={N}; P=0
    while P < K:
        X=max(S)
        XR=ceil((X-1)/2)
        XL=floor((X-1)/2)
        P=P+C[X]
        S.remove(X); S.add(XL); S.add(XR)
 #       print(XR,XL)
        C[XL]+=C[X]; C[XR]+=C[X]
    print('Case #{}: {} {}'.format(t+1,XR,XL))

📓 Variant 1. SageMath Interactive


📓 Variant 2. Python Only




📓 Variant 2. SageMath Interactive