| Task: | Spiraali |
| Sender: | masuman |
| Submission time: | 2021-10-06 21:52:43 +0300 |
| Language: | Python3 (CPython3) |
| Status: | READY |
| Result: | 35 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 15 |
| #2 | ACCEPTED | 20 |
| #3 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.03 s | 1 | details |
| #2 | ACCEPTED | 0.04 s | 2 | details |
| #3 | WRONG ANSWER | 0.04 s | 3 | details |
Code
def r(y,x,n,xx):
return max(abs(int(xx[0]) - y),abs(int(xx[1]) - x))
def ring(y,x,n):
nw = (n/2, n/2)
ne = (n/2, (n/2)+1)
se = ((n/2)+1,(n/2)+1)
sw = ((n/2)+1, n/2)
if x <= n/2 and y <= n/2:
return int(r(y,x,n,nw))
if x > n/2 and y <= n/2:
return int(r(y,x,n,ne))
if x <= n/2 and y > n/2:
return int(r(y,x,n,sw))
if x > n/2 and y > n/2:
return int(r(y,x,n,se))
def ringCount(y,x,n):
yNew = y - ((n/2)-1-ring(y,x,n))
xNew = x - ((n/2)-1-ring(y,x,n))
return (int(yNew), int(xNew))
def runningNumber(y,x,p):
p = (p+1)*2
if (y,x) == (1,1):
return 1
if (y,x) == (p,1):
return p
if (y,x) == (p,p):
return 2*p - 1
if (y,x) == (1, p):
return 3*p - 2
if y == 1:
return 4*p-2-x
if y == p:
return x+p-1
if x == 1:
return y
if x == p:
return 3*p-1-y
def s(n,p):
return int(4*p*(n-p))
def f(y,x,n):
k = ringCount(y,x,n)
g = ring(y,x,n)
p = runningNumber(k[0],k[1], g)
d = (n/2)-g-1
e = s(n, d)
print(e+p)
a, b = input().split()
n = int(a)
t = int(b)
for i in range(t):
a, b = input().split()
y = int(a)
x = int(b)
f(y,x,n)
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: WRONG ANSWER
| input |
|---|
| 1000000000 1000 177757853 827347032 409613589 419171337 739269360 256524697 328695530 896842209 ... |
| correct output |
|---|
| 571375684522141210 967321186816598569 762879105851175000 370065046779516790 936897883750373771 ... |
| user output |
|---|
| 571375684522141210 967321186816598633 762879105851175000 370065046779516794 93689788375037 ... Truncated |
