Task: | Spiraali |
Sender: | jogr |
Submission time: | 2021-10-04 14:18:10 +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.03 s | 2 | details |
#3 | WRONG ANSWER | 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 = 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): y, x=input().split() x=int(x) y=int(y) print("%d" % getspiral(x, y))
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 |
---|
571375684522141184 967321186816598569 762879105851175000 370065046779516800 93689788375037 ... Truncated |