CSES - Datatähti 2021 alku - Results
Submission details
Task:Ratsun reitit
Sender:Totska
Submission time:2021-08-19 14:25:39 +0300
Language:Python3 (PyPy3)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.07 s1, 2, 3details
#20.07 s1, 2, 3details
#30.07 s1, 2, 3details
#40.07 s1, 2, 3details
#50.07 s1, 2, 3details
#60.07 s1, 2, 3details
#70.07 s1, 2, 3details
#80.07 s2, 3details
#90.07 s2, 3details
#100.07 s2, 3details
#110.07 s3details
#120.07 s3details
#130.07 s3details

Code

n = input()
shortestpath = {}

for i in range(n):
    for j in range(n):
        shortestpath[(i, j)] = 999999

start = (0, 0)
shortestpath[start] = 0

length = 0

def getneighbours(node):
    neighbours = []
    
    offsets = ((1, 2), (2, 1), (-1, 2), (2, -1), (-1, -2), (-2, -1), (1, -2), (-2, 1))
    
    for i in range(8):
        newnode = (node[0]+offsets[i][0], node[1]+offsets[i][1])
        
        if 0 <= newnode[0] < n and 0 <= newnode[1] < n:
            neighbours.append(newnode)
    
    return neighbours
    
def visit(node, length):
    length += 1
    neighbours = getneighbours(node)
    
    for newnode in neighbours:
        if length < shortestpath[newnode]:
            shortestpath[newnode] = length
            
            visit(newnode, length)
            
#print(getneighbours((2,2)))
visit(start, length)
#print(shortestpath)


for r in range(n):
    row = ""
    for c in range(n):
        row += f"{shortestpath[(r, c)]} "
    
    print(row)

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
4

correct output
0 3 2 5 
3 4 1 2 
2 1 4 3 
5 2 3 2 

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 4, in <module>
    for i i...

Test 2

Group: 1, 2, 3

Verdict:

input
5

correct output
0 3 2 3 2 
3 4 1 2 3 
2 1 4 3 2 
3 2 3 2 3 
2 3 2 3 4 

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 4, in <module>
    for i i...

Test 3

Group: 1, 2, 3

Verdict:

input
6

correct output
0 3 2 3 2 3 
3 4 1 2 3 4 
2 1 4 3 2 3 
3 2 3 2 3 4 
2 3 2 3 4 3 
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 4, in <module>
    for i i...

Test 4

Group: 1, 2, 3

Verdict:

input
7

correct output
0 3 2 3 2 3 4 
3 4 1 2 3 4 3 
2 1 4 3 2 3 4 
3 2 3 2 3 4 3 
2 3 2 3 4 3 4 
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 4, in <module>
    for i i...

Test 5

Group: 1, 2, 3

Verdict:

input
8

correct output
0 3 2 3 2 3 4 5 
3 4 1 2 3 4 3 4 
2 1 4 3 2 3 4 5 
3 2 3 2 3 4 3 4 
2 3 2 3 4 3 4 5 
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 4, in <module>
    for i i...

Test 6

Group: 1, 2, 3

Verdict:

input
9

correct output
0 3 2 3 2 3 4 5 4 
3 4 1 2 3 4 3 4 5 
2 1 4 3 2 3 4 5 4 
3 2 3 2 3 4 3 4 5 
2 3 2 3 4 3 4 5 4 
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 4, in <module>
    for i i...

Test 7

Group: 1, 2, 3

Verdict:

input
10

correct output
0 3 2 3 2 3 4 5 4 5 
3 4 1 2 3 4 3 4 5 6 
2 1 4 3 2 3 4 5 4 5 
3 2 3 2 3 4 3 4 5 6 
2 3 2 3 4 3 4 5 4 5 
...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 4, in <module>
    for i i...

Test 8

Group: 2, 3

Verdict:

input
25

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 4, in <module>
    for i i...

Test 9

Group: 2, 3

Verdict:

input
49

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 4, in <module>
    for i i...

Test 10

Group: 2, 3

Verdict:

input
50

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 4, in <module>
    for i i...

Test 11

Group: 3

Verdict:

input
75

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 4, in <module>
    for i i...

Test 12

Group: 3

Verdict:

input
99

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 4, in <module>
    for i i...

Test 13

Group: 3

Verdict:

input
100

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 4, in <module>
    for i i...