I was doing the Target Shooting task of the 2013 Olympiad of Computing (OBI) level 2, which can be found here , and I was able to do without great difficulties. The task was to figure out how many points a person would make by shooting at a target, considering that she would gain one point at each circumference that each shot was internal or belonged. The input of the program consists of the number of circles (all whose center is in (0,0)) and their rays and the number of shots and their coordinates. The output is just the number of points the person would make.
Well, so far so good - my code works. The problem is that in the official OBI tester, which can be found here , I received many results with timeout exceeded and I ended up with only 20 points out of 100 possible. I wanted help, therefore, to improve the performance of my program.
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
def calcula_pontos():
qtd_circulos, qtd_tiros = raw_input().split()
raios_circulos = [float(raw_input()) for circulo in range(int(qtd_circulos))]
cord_tiros = [raw_input().split() for tiro in range(int(qtd_tiros))]
pontos = 0
for x, y in cord_tiros:
for raio in raios_circulos:
if((int(x) ** 2) + (int(y) ** 2) > (raio ** 2)):
continue
else:
pontos += 1
print pontos
calcula_pontos()