56702023-09-07 10:37:38KezdőVizeskannákpython3Accepted 40/4072ms26168 KiB
A,B,C = [int(i) for i in input().split()]
X = int(input())

def ont(S):
    a,b,c = S
    L = []
    if a > 0:
        if b < B:
            x = min(a,B-b)
            L.append((a-x,b+x,c))
        if c < C:
            x = min(a,C-c)
            L.append((a-x,b,c+x))
    if b > 0:
        if a < A:
            x = min(b,A-a)
            L.append((a+x,b-x,c))
        if c < C:
            x = min(b,C-c)
            L.append((a,b-x,c+x))
    if c > 0:
        if a < A:
            x = min(c,A-a)
            L.append((a+x,b,c-x))
        if b < B:
            x = min(c,B-b)
            L.append((a,b+x,c-x))
    return L

def BFS(S):
    sor = [S]
    lepes = {}
    lepes[S] = 0
    while sor != []:
        P = sor.pop(0)
        L = ont(P)
        for viz in L:
            if viz not in lepes:
                sor.append(viz)
                lepes[viz] = lepes[P] + 1
                if X in viz:
                    return lepes[viz]
    return -1

if A == X:
    print(0)
else:
    print(BFS((A,0,0)))

                     
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/023ms17460 KiB
2Accepted0/017ms17944 KiB
3Accepted1/117ms18028 KiB
4Accepted1/117ms18192 KiB
5Accepted1/118ms18516 KiB
6Accepted1/117ms18480 KiB
7Accepted1/117ms18788 KiB
8Accepted1/117ms18912 KiB
9Accepted1/117ms19348 KiB
10Accepted1/117ms19392 KiB
11Accepted1/117ms19524 KiB
12Accepted1/117ms19520 KiB
13Accepted2/217ms19772 KiB
14Accepted2/218ms19812 KiB
15Accepted2/217ms20080 KiB
16Accepted2/217ms20076 KiB
17Accepted2/217ms20092 KiB
18Accepted2/217ms20080 KiB
19Accepted2/217ms20108 KiB
20Accepted2/220ms20580 KiB
21Accepted2/217ms20276 KiB
22Accepted2/217ms20512 KiB
23Accepted2/219ms20700 KiB
24Accepted2/252ms24068 KiB
25Accepted2/241ms23048 KiB
26Accepted2/272ms26168 KiB
27Accepted2/263ms24920 KiB