107922024-04-12 20:11:1342Táblajáték 2 (70 pont)python3Accepted 70/7017ms13460 KiB
from sys import stdin
input=stdin.readline

def main():
    N=int(input())
    K = [int(x) for x in input().split()]
    a=b=0
    for k in K:
        if k==4:
            b-=1
        elif k==5:
            b+=1
        elif k==0:
            a+=1
            b=b*3
        elif k==1:
            a+=1
            b=b*3+1
        elif k==2:
            a+=1
            b=b*3+2
        elif k==3:
            a-=1
            b//=3
    print(a)
    res=[]
    while b:
        res.append(str(b%3))
        b//=3
    if len(res)!=0:
        print(''.join(res[::-1]))
    else:
        print(0)
        
main()
SubtaskSumTestVerdictTimeMemory
base70/70
1Accepted0/017ms11548 KiB
2Accepted0/017ms11816 KiB
3Accepted2/217ms11520 KiB
4Accepted3/317ms12036 KiB
5Accepted3/317ms12220 KiB
6Accepted3/317ms12444 KiB
7Accepted3/317ms12496 KiB
8Accepted3/317ms12616 KiB
9Accepted3/317ms12960 KiB
10Accepted3/317ms12848 KiB
11Accepted3/317ms12964 KiB
12Accepted3/317ms12892 KiB
13Accepted3/317ms13320 KiB
14Accepted3/317ms12956 KiB
15Accepted4/417ms12972 KiB
16Accepted4/417ms13128 KiB
17Accepted4/417ms13460 KiB
18Accepted4/417ms13124 KiB
19Accepted4/417ms13312 KiB
20Accepted4/417ms13176 KiB
21Accepted4/417ms13344 KiB
22Accepted4/417ms13316 KiB
23Accepted3/317ms13236 KiB