为什么我的代码会出现超时错误?

时间:2018-05-31 04:34:12

标签: python python-3.x algorithm

我正在尝试在Hackerrank上解决这个问题:https://www.hackerrank.com/challenges/save-the-prisoner/problem

我的问题是我的代码在每个测试用例中都给出了超时错误,除了样本和测试用例#4。这是我的代码:

t = int(input())
store = []
for t_itr in range(t):
    nms = input().split()
    n = int(nms[0])
    m = int(nms[1])
    s = int(nms[2])
    for i in range (0,m):
        store.append(i % n + s)
    print(store[-1])

如何在不超出测试用例超时的情况下让代码更快地运行?

1 个答案:

答案 0 :(得分:1)

您需要在某个标识符上拆分(第4行)。

相关问题