| Task: | Spiraali |
| Sender: | jogr |
| Submission time: | 2021-10-04 15:08:54 +0300 |
| Language: | Python3 (CPython3) |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 15 |
| #2 | ACCEPTED | 20 |
| #3 | ACCEPTED | 65 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.02 s | 1 | details |
| #2 | ACCEPTED | 0.03 s | 2 | details |
| #3 | ACCEPTED | 0.03 s | 3 | details |
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 = int(0)
xn = int(0)
if x > n/2:
xn = int(x - n/2)
xn = int(n/2-xn)
else:
xn = int(x-1)
if y > n/2:
yn = int(y - n/2)
yn = int(n/2-yn)
else:
yn = int(y-1)
level = int(min(yn, xn))
l=level
#print(f"level: {level}")
#print(f"bounds: {lbounds(l)}")
#print(f"edge length: {ledge(l)}")
outn = int(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 + int(y - lbounds(l)[0])
elif x == lbounds(l)[1]:
# right edge
outn += (2*ledge(l)-1)
return outn + int(lbounds(l)[1] - y)
elif y == lbounds(l)[0]:
# top edge
outn += (3*ledge(l)-2)
return outn + int(lbounds(l)[1] - x)
elif y == lbounds(l)[1]:
# bottom edge
outn += (ledge(l))
return outn + int(x - lbounds(l)[0])
return int(outn)
outs = ""
for i in range(0, t):
y, x=input().split()
x=int(x)
y=int(y)
outs += "%d" % getspiral(x, y)
if i+1 != t:
outs += "\n"
print(outs)
Test details
Test 1
Group: 1
Verdict: ACCEPTED
| input |
|---|
| 10 100 1 1 1 2 1 3 1 4 ... |
| correct output |
|---|
| 1 36 35 34 33 ... |
| user output |
|---|
| 1 36 35 34 33 ... Truncated |
Test 2
Group: 2
Verdict: ACCEPTED
| input |
|---|
| 1000 1000 371 263 915 322 946 880 53 738 ... |
| correct output |
|---|
| 773533 312166 206053 200080 593922 ... |
| user output |
|---|
| 773533 312166 206053 200080 593922 ... Truncated |
Test 3
Group: 3
Verdict: ACCEPTED
| input |
|---|
| 1000000000 1000 177757853 827347032 409613589 419171337 739269360 256524697 328695530 896842209 ... |
| correct output |
|---|
| 571375684522141210 967321186816598569 762879105851175000 370065046779516790 936897883750373771 ... |
| user output |
|---|
| 571375684522141210 967321186816598569 762879105851175000 370065046779516790 93689788375037 ... Truncated |
