Saturday, April 9, 2022

📑 Punched Cards 2

Codejam Qualification Round 2022. Task 1 Variant 2

Python Only

def gen_table(r,c):
    for i in range(2*r+1):
        for j in range(2*c+1):
            if (i < 2 and j < 2):
                yield '.'
            else:
                el=((j+1)%2)*((i+1)%2)*'+'+\
                   (j%2)*((i+1)%2)*'-'+\
                   ((j+1)%2)*(i%2)*'|'+\
                   (j%2)*(i%2)*'.'
                yield el
        yield '\n'
T=int(input())
for t in range(T):
    N=input()
    [R,C]=[int(n) for n in N.split()]
    gen=gen_table(R,C)
    print('Case #{}:'.format(t+1))
    print(''.join(gen))


📑 Double or One

Codejam 1A Round 2022. Task 1

Python Only

T=int(input())
for t in range(T):
    S=input()
    NS=''; i=0; temp=''
    while i < len(S)-1:
        if (len(set(S[i:])) == 1) and (len(S[i:]) > 1):
            NS+=S[i:-1]
            break
        else:
            if S[i+1] > S[i]:
                NS+=2*temp+2*S[i]
                temp=''
            elif S[i+1] < S[i]:
                NS+=temp+S[i]
                temp=''
            else:
                temp+=S[i]
        i+=1  
    print('Case #{}: {}'.format(t+1,NS+S[-1]))


def gen_first(S):
    i=0; temp=''
    while i < len(S)-1:
        if (len(set(S[i:])) == 1) and (len(S[i:]) > 1):
            yield S[i:-1]
            break
        else:
            if S[i+1] > S[i]:
                yield 2*temp+2*S[i]
                temp=''
            elif S[i+1] < S[i]:
                yield temp+S[i]
                temp=''
            else:
                temp+=S[i]
        i+=1
    yield S[-1]
T=int(input())
for t in range(T):
    S=input()
    NS=''.join(gen_first(S))
    print('Case #{}: {}'.format(t+1,NS))


Sunday, April 3, 2022

📑 Dice Rows

Codejam Qualification Round 2022. Task 3

Python Only

T=int(input())
for t in range(T):
    N=int(input())
    S=input()
    k=N
    if k>4:
        S=sorted([int(s) for s in S.split()])[::-1]
        k=N=min([N,S[0]])
        for i in range(N):
            if S[i] < N-i:
                k-=1
    print('Case #{}: {}'.format(t+1,k))


📑 3D Printing

Codejam Qualification Round 2022. Task 2

Python Only

T=int(input())
for t in range(T):
    C,M,Y,K=[],[],[],[]
    for i in range(3):
        N=input()
        N=[int(n) for n in N.split()]
        C+=[N[0]]; M+=[N[1]]; Y+=[N[2]]; K+=[N[3]]
    c,m,y,k=min(C),min(M),min(Y),min(K)
    if c+m+y+k<10**6:
        R='IMPOSSIBLE'
    else:
        m=min([m,10**6-c])
        y=min([y,10**6-c-m])
        k=10**6-c-m-y
        R='{} {} {} {}'.format(c,m,y,k)
    print('Case #{}: {}'.format(t+1,R))


📑 Punched Cards

Codejam Qualification Round 2022. Task 1


Python Only

T=int(input())
for t in range(T):
    N=input()
    print('Case #{}:'.format(t+1))
    [R,C]=[int(n) for n in N.split()]
    str1='..+-+'+(C-2)*'-+'
    str2='..|.|'+(C-2)*'.|'
    str3='+-+-+'+(C-2)*'-+'
    str4='|.|.|'+(C-2)*'.|'
    [print(el) for el in [str1,str2,str3,str4,str3]]
    for i in range(R-2):
        print(str4)
        print(str3)