Google Kickstart B轮2020年

时间:2020-07-31 17:40:41

标签: python

我对编程还很陌生,但是今天我试图解决Google Kickstart 2020 B轮“公交路线”中的问题: https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ffc8/00000000002d83bf

我的程序可以很好地处理示例案例,但是当涉及到测试集时,就会遇到“运行时错误”。我真的不知道为什么会这样,如果有人可以帮助我指出我的错误,我将不胜感激。这是我的代码:

t = int(input())
tc = 0
def check_valid(day, bus_route, index, max_day):
    if index >= len(bus_route):
        return True
    if day % bus_route[index] == 0 and day <= max_day:
        return all([check_valid(day, bus_route, index + 1, max_day)])
    elif (day + 1) % bus_route[index] == 0 and (day+1) <= max_day:
        return all([check_valid(day + 1, bus_route, index + 1, max_day)])
    return False
while t > 0:
    bus_route_number, max_day = map(int, input().split())
    route = list(map(int, input().split()))
    latest = 0
    if all([max_day % i == 0 for i in route]):
        latest = max_day
    else:
        for day in range(max_day, 0 , -1):
            if check_valid(day, route, 0, max_day):
                latest = day
                break
    tc += 1
    print("Case #" + str(tc) +":", str(latest))
    t -= 1

0 个答案:

没有答案