我正在尝试应对 Codejam 挑战,我的主要编程语言是 Python,因此我也在使用 Python 解决我面临的所有问题。然而,我已经开始TLE
使用看起来不错并且与分析中描述的解决方案相对应的代码。因此,我正在研究使用 Cython 来尝试加速我的代码的选项。我可以在本地计算机上使用它,我或多或少地了解它的工作原理。从我在互联网上收集的信息来看,google code jam 似乎允许使用 Cython,但我真的不知道如何使用它。
例如,我最近尝试New Elements : Part 1
从 google code jam 2019 解决:第 2 轮(见下文)。我应该采取哪些实际步骤来使这个解决方案使用 Cython 运行得更快?我不要求任何有关如何改进此代码的建议,只是要求如何能够在 codejam 环境中使用 Cython。
T=int(input())
for t in range(1, T+1):
N=int(input())
CJ_list=list()
possible=True
for n in range(N):
C, J = map(int, input().split())
CJ_list.append((C, J))
ls_crossings=list()
for n1, CJ1 in enumerate(CJ_list):
if not possible:
break
for n2, CJ2 in enumerate(CJ_list):
if n1<=n2:
continue
if CJ1==CJ2:
possible=False
break
if CJ1[0] == CJ2[0] or CJ1[1] == CJ2[1]:
continue
teller=(CJ2[1]-CJ1[1])
noemer=(CJ1[0] - CJ2[0])
if (teller * noemer < 0):
continue
is_duplicate=False
for crossing in ls_crossings:
if crossing[0]*noemer==crossing[1]*teller:
is_duplicate=True
break
if not is_duplicate:
ls_crossings.append((teller, noemer))
if possible:
print("Case #{}: {}".format(t, len(ls_crossings)+1))
else:
print("Case #{}: {}".format(t, 0))