Google Kick Start问题“公交路线”超出内存限制

时间:2020-07-13 16:10:04

标签: python

我正在练习反冲启动问题“公共汽车路线”,尽管我的解决方案正确,但是却遇到了内存限制超出问题,并且我不确定为什么。这是问题的链接: https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ffc8/00000000002d83bf

下面是我的代码(用python3编写):

T = int(input())
for i in range(T):

    numBuses, maxDays = map(int, input().split())
    busArray = list(map(int, input().split()[:numBuses]))

    possibleDays = list(range(busArray[0], maxDays+1, busArray[0]))
    while(len(possibleDays) > 1):
        startIndex = len(possibleDays)//2
        startDay = possibleDays[startIndex]
        busIterator = 0
        for currentDay in range(startDay, maxDays+1):
            while(busIterator < len(busArray) and currentDay % busArray[busIterator] == 0):
                busIterator += 1
    
        if(busIterator == (len(busArray))):
            possibleDays = possibleDays[startIndex:]
        
        else:
            possibleDays = possibleDays[:startIndex]

    print("Case #" + str(i+1) + ": " + str(possibleDays[0]))

0 个答案:

没有答案