TOPIC

Time limit exceeded

avanessa1 asked 2 years ago

Quando testo, sai o resultado esperado, mas precisa de alguma otimização, já que quanto mando o código retorna o erro de Time limit exceeded. Alguma ajuda?

When I test it, it the output is whats supposed to be, but it need some adjustment, because when i send it to URI it returns to me "Time limit exceeded". Some help? .......................................................................................................................................................................................................................................

T = int(input())

from math import sqrt

fire = [200, 20, 30, 50]

water = [300, 10, 25, 40]

earth = [400, 25, 55, 70]

air = [100, 18, 38, 60]

for t in range(T): w, h, x0, y0 = list(map(int, input().split()))

magia, N, cx, cy = input().split()

dano = 0

if magia == "fire":
    raio = fire[int(N)]

    D = fire[0]

elif magia == "water":
    raio = water[int(N)]

    D = water[0]

elif magia == "earth":
    raio = earth[int(N)]

    D = earth[0]

else:
    raio = air[int(N)]

    D = air[0]

for L in range(w):
    for C in range(h):
        distancia = sqrt((int(cx) - x0) ** 2 + (int(cy) - y0) ** 2)

        if distancia <= raio:
            dano = D

            break

        x0 += 1

        y0 += 1

print(dano)

Remember not post solutions. Your post may be reviewed by our moderators.

  • AlexMorte replied 2 years ago

    Alana, você não pode testar todas as posições. O maior retângulo é 1000x1000 = 10⁶ e podem existir 1000 casos de testes, 10⁹ o que já beira o limite de 1 segundo, por mais rápida que qualquer operaçaõ seja.