CSES - Datatähti 2022 alku - Results
Submission details
Task:Spiraali
Sender:jogr
Submission time:2021-10-04 14:29:50 +0300
Language:CPython3
Status:READY
Result:35
Feedback
groupverdictscore
#1ACCEPTED15
#2ACCEPTED20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.02 s1details
#2ACCEPTED0.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)
        
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
...

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
...

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
571375684522141184
967321186816598569
762879105851175000
370065046779516800
936897883750373771
...