CSES - DatatÃ¤hti 2022 alku - Results
 Task: Spiraali (Spiral) Sender: jogr Submission time: 2021-10-04 14:16:56 Language: CPython3 Status: READY Result: 0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.03 s1details
#20.03 s2details
#30.03 s3details

Code

n, t=input().split()
n=int(n)
t=int(t)

def le(l):
return n-(2*l)

def ledge(l):
return n-(2*l)

def ps(l):
edgeL = le(l)
return edgeL * 2 + (edgeL - 2) * 2

def ls(l):
return-4*(l**2)+((4*n)*l)

def lbounds(l):
return (l+1, n-l)

def getspiral(x, y):
yn = 0
xn = 0
if x > n/2:
xn = x - n/2
xn = n/2-xn
else:
xn = x-1
if y > n/2:
yn = y - n/2
yn = n/2-yn
else:
yn = y-1
level = min(yn, xn)
l=level
#print(f"level: {level}")
#print(f"bounds: {lbounds(l)}")
#print(f"edge length: {ledge(l)}")
outn = ls(level)

#print(f"levels under sum: {ls(l)}")

if x==1 and y==1:
return 1

if x == lbounds(l)[0]:
# left edge
outn += 1
return outn + (y - lbounds(l)[0])
elif x == lbounds(l)[1]:
# right edge
outn += (2*ledge(l)-1)
return outn + (lbounds(l)[1] - y)
elif y == lbounds(l)[0]:
# top edge
outn += (3*ledge(l)-2)
return outn + (lbounds(l)[1] - x)
elif y == lbounds(l)[1]:
# bottom edge
outn += (ledge(l))
return outn + (x - lbounds(l)[0])
return int(outn)

for i in range(0, t):
x, y=input().split()
x=int(x)
y=int(y)
print("%d" % getspiral(x, y))

Test details

Group: 1

Verdict:

input
10 100
1 1
1 2
1 3
1 4
...

correct output
1
36
35
34
33
...

user output
1
2
3
4
5
...

Group: 2

Verdict:

input
1000 1000
371 263
915 322
946 880
53 738
...

correct output
773533
312166
206053
200080
593922
...

user output
775217
313352
206185
197870
594540
...

Test 3

Group: 3

Verdict:

input
1000000000 1000
177757853 827347032
409613589 419171337
739269360 256524697
328695530 896842209
...

correct output
571375684522141210
967321186816598569
762879105851175000
370065046779516790
936897883750373771
...

user output
571375683222962880
967321186112622773
762879106833488102
370065045643223424
936897882780397411
...