CSES - Datatähti 2021 alku - Results
Submission details
Task:Ratsun reitit
Sender:jkan
Submission time:2020-10-04 20:21:49 +0300
Language:CPython3
Status:READY
Result:27
Feedback
groupverdictscore
#1ACCEPTED27
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.02 s1, 2, 3details
#2ACCEPTED0.02 s1, 2, 3details
#3ACCEPTED0.02 s1, 2, 3details
#4ACCEPTED0.03 s1, 2, 3details
#5ACCEPTED0.03 s1, 2, 3details
#6ACCEPTED0.03 s1, 2, 3details
#7ACCEPTED0.03 s1, 2, 3details
#8ACCEPTED0.20 s2, 3details
#9--2, 3details
#10--2, 3details
#110.04 s3details
#120.04 s3details
#130.04 s3details

Code

def recurse_knight(board, pos, depth):
    # All possible knight moves from origin
    moves = [
        (-2,-1),
        (-1,-2),
        (1,-2),
        (2, -1),
        (2,1),
        (1,2),
        (-1,2),
        (-2,1),
    ]
    moves = list(filter(
        # Filter out moves out of bounds
        lambda t: 0 <= t[0] < len(board) and  0 <= t[1] < len(board[1]),
        map(
            # Find all moves from pos
            lambda t: (t[0]+pos[0], t[1]+pos[1]),
            moves
        )
    ))
    done = []
    for move in moves:
        # Perform every move which reaches a new tile
        if board[move[0]][move[1]] is None or board[move[0]][move[1]] > depth:
            board[move[0]][move[1]] = depth
            done += [move]
    for move in done:
        # Recurse for each newly done move
        recurse_knight(board, move, depth+1)

def pretty_print_matrix(m):
    return "\n".join(map(lambda x:" ".join(map(str,x)), m))

board = []
n = int(input())
for x in range(n):
    board += [[]]
    for y in range(n):
        board[-1] += [None]

board[0][0] = 0;
recurse_knight(board,(0,0),1);
print(
    pretty_print_matrix(board)
)





Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
4

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

user output
0 3 2 5
3 4 1 2
2 1 4 3
5 2 3 2

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

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

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

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

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

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

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

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

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

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

Test 7

Group: 1, 2, 3

Verdict: ACCEPTED

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

Test 8

Group: 2, 3

Verdict: ACCEPTED

input
25

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

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

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)

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)

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 43, in <module>
    recurse_knight(board,(0,0),1);
  File "input/code.py", line 30, in recurse_knight
    recurse_knight(board, move, depth+1)
  File "input/code.py", line 30, in recurse_knight
    recurse_knight(board, move, depth+1)
  File "input/code.py", line 30, in recurse_knight
    recurse_knight(board, move, depth+1)
  [Previous line repeated 992 more times]
  File "input/code.py", line 19, in recurse_knight
    moves
  File "input/code.py", line 15, in <lambda>
    lambda t: 0 <= t[0] < len(board) and  0 <= t[1] < len(board[1]),
RecursionError: maximum recursion depth exceeded in comparison

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 43, in <module>
    recurse_knight(board,(0,0),1);
  File "input/code.py", line 30, in recurse_knight
    recurse_knight(board, move, depth+1)
  File "input/code.py", line 30, in recurse_knight
    recurse_knight(board, move, depth+1)
  File "input/code.py", line 30, in recurse_knight
    recurse_knight(board, move, depth+1)
  [Previous line repeated 992 more times]
  File "input/code.py", line 19, in recurse_knight
    moves
  File "input/code.py", line 15, in <lambda>
    lambda t: 0 <= t[0] < len(board) and  0 <= t[1] < len(board[1]),
RecursionError: maximum recursion depth exceeded in comparison

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 43, in <module>
    recurse_knight(board,(0,0),1);
  File "input/code.py", line 30, in recurse_knight
    recurse_knight(board, move, depth+1)
  File "input/code.py", line 30, in recurse_knight
    recurse_knight(board, move, depth+1)
  File "input/code.py", line 30, in recurse_knight
    recurse_knight(board, move, depth+1)
  [Previous line repeated 992 more times]
  File "input/code.py", line 19, in recurse_knight
    moves
  File "input/code.py", line 15, in <lambda>
    lambda t: 0 <= t[0] < len(board) and  0 <= t[1] < len(board[1]),
RecursionError: maximum recursion depth exceeded in comparison