用4x4的矩形验算都是正确的,大的矩形第10个和第100个数值也都是正确的,不知道错哪了。。。from numba import jit
import numpy as np
@jit
def gen_s():
s = np.zeros(4000000, dtype='int64')
for k in range(0, 55):
s[k] = (100003-200003*(k+1)+300007*(k+1)**3) % 1000000 - 500000
for k in range(55, 4000000):
s[k] = (s[k-24]+s[k-55]+1000000) % 1000000 - 500000
return s.reshape(2000,2000)
@jit
def get_max_w(s):
return np.max(np.sum(s, axis=1))
@jit
def get_max_d(s):
return np.max(np.sum(s, axis=0))
@jit
def get_max_l(s, n):
maxsum = 0
for line in range(n):
total = 0
y = line
x = 0
while x<n and y<n:
total += s[x,y]
x += 1
y += 1
maxsum = max(maxsum, total)
for line in range(n-1,-1,-1):
total = 0
y = line
x = n-1
while x>=0 and y>=0:
total += s[x,y]
x -= 1
y -= 1
maxsum = max(maxsum, total)
return maxsum
@jit
def get_max_r(s, n):
maxsum = 0
for line in range(n-1,-1,-1):
total = 0
y = line
x = 0
while x<n and y>=0:
total += s[x,y]
x += 1
y -= 1
maxsum = max(maxsum, total)
for line in range(n):
total = 0
y = line
x = n-1
while x>=0 and y<n:
total += s[x,y]
x -= 1
y += 1
maxsum = max(maxsum, total)
return maxsum
@jit
def solve():
s = gen_s()
return get_max_d(s),get_max_w(s),get_max_l(s, 2000),get_max_r(s, 2000)
print(solve())
(48519449, 44540336, 43117448, 40358088)
[Finished in 2.8s] |