CSES - Datatähti 2021 alku - Results
Submission details
Task:Ratsun reitit
Sender:jmarttinen
Submission time:2020-09-28 14:31:21 +0300
Language:CPython3
Status:READY
Result:58
Feedback
groupverdictscore
#1ACCEPTED27
#2ACCEPTED31
#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.06 s2, 3details
#9ACCEPTED0.55 s2, 3details
#10ACCEPTED0.59 s2, 3details
#11--3details
#12--3details
#13--3details

Code

# Author: Jussi Marttinen
# Last edited: 2020/09/28
# My solution for Datatähti 2020

from itertools import product


longparts = (-2, 2)
shortparts = (-1, 1)
legal_jumps = list(product(longparts, shortparts)) + list(product(shortparts, longparts))



def calc_tile(board, x, y):
    n = len(board)
    for x0, y0 in legal_jumps:
        if (x + x0 in range(n)) and (y + y0 in range(n)):
            tile = board[y+y0][x+x0]
        
            if (tile > board[y][x] + 1) or (tile == 0):
                board[y+y0][x+x0] = board[y][x] + 1
                board[0][0] = 0
                calc_tile(board, x + x0, y + y0)

def calc_board(board):
    n = len(board)
    done = [(0,0)]
    queue = [(0,0)]

    while queue:
        x, y = queue.pop(0)

        for x0, y0 in legal_jumps:
            X, Y = x + x0, y + y0
            if (X in range(n)) and (Y in range(n)) and ((X,Y) not in done):
                board[Y][X] = board[y][x] + 1
                done.append((X, Y))
                queue.append((X, Y))
                



n = int(input())
# creates an n*n nested list
board = [[0]*n for _ in range(n)]

calc_board(board)





print("\n".join((" ".join((str(t) for t in row)) for row in 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: ACCEPTED

input
49

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 10

Group: 2, 3

Verdict: ACCEPTED

input
50

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

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)

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)