# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
973906 |
2024-05-02T12:39:48 Z |
canadavid1 |
Spiral (BOI16_spiral) |
Python 3 |
|
18 ms |
3164 KB |
def E(poly,num):return sum(v*num**i for i,v in enumerate(poly))
def r(x,y):
X=abs(x);Y=abs(y);n=min(X,Y);N=max(X,Y)
L=X<Y
rp=[[[13,15,8],[19,-21,8]],[[19,21,8],[13,-15,8]]][L][[x,y][L]>=0]
f=n-([y,x][L]>=0)
return (E([[[-1,2,4,2],[0,4,0,2]],[[-4,10,0,2],[1,2,-4,2]]][x>=0][y>=0],n)+(N*E(rp,N)-n*E(rp,n))//6)*n+((N-n)*f*(f+1))//2*(-1 if(L!=(x >= 0))!=(y>=0)else 1)-8*y*(0<-y<x)
def R(x,y,X,Y):
X+=1;Y+=1;x=[x,X];y=[y,Y];s=0
for a in [0,1]:
for b in [0,1]:s+=r(x[a],y[b])*(1 if(x[0]*x[1]>0 and abs(x[a])<abs(x[1-a]))==(y[0]*y[1]>0 and abs(y[b])<abs(y[1-b]))else -1)
return s%(10**9+7)
for i in range(int(input().split()[1])):
print(R(*map(int,input().split())))
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
2908 KB |
Output is correct |
2 |
Correct |
14 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
3128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
2908 KB |
Output is correct |
2 |
Correct |
15 ms |
2908 KB |
Output is correct |
3 |
Correct |
14 ms |
2908 KB |
Output is correct |
4 |
Correct |
14 ms |
3128 KB |
Output is correct |
5 |
Correct |
18 ms |
3164 KB |
Output is correct |