0
現在、HackerRankでは、Circular Array Rotationの問題を解決しようとしています。ほとんどのテストケースが機能しますが、一部は「タイムアウトのために終了しました」。HackerRank Python - いくつかのテストケースが「タイムアウトのために終了しました」というコードをどのように最適化できますか?
コードを変更して最適化するにはどうすればよいですか?
#!/bin/python3
import sys
n,k,q = input().strip().split(' ')
n,k,q = [int(n),int(k),int(q)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
m = []
for a0 in range(q):
m.append(int(input().strip()))
for i in range (0, k % n):
temp = a[n-1] # Stores the last element temporarily
a.pop(n-1) # Removes the last element
a = [temp] + a # Appends the temporary element to the start (prepends)
for i in range (0, q):
print(a[m[i]])
これはおそらくhttp://codereview.stackexchange.com/に適しています。 – wflynny