CSES - Datatähti 2021 alku - Results
Submission details
Task:Ratsun reitit
Sender:Sartec
Submission time:2020-10-02 19:04:25 +0300
Language:Python3 (CPython3)
Status:READY
Result:27
Feedback
groupverdictscore
#1ACCEPTED27
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.02 s1, 2, 3details
#2ACCEPTED0.03 s1, 2, 3details
#3ACCEPTED0.03 s1, 2, 3details
#4ACCEPTED0.03 s1, 2, 3details
#5ACCEPTED0.03 s1, 2, 3details
#6ACCEPTED0.04 s1, 2, 3details
#7ACCEPTED0.05 s1, 2, 3details
#8ACCEPTED0.81 s2, 3details
#9--2, 3details
#10--2, 3details
#11--3details
#12--3details
#13--3details

Code

import time

start_time = time.time()

n2 = int(input(""))

dp = [[i+1 for i in range(n2)] for j in range(n2)];

class cell:

    def __init__(self, x = 0, y = 0, dist = 0):
        self.x = x
        self.y = y
        self.dist = dist

if n2 < 4:
    print("n has to greater than 3")
else:

    # Python3 code to find minimum steps to reach
    # to specific cell in minimum moves by Knight

    # checks whether given position is
    # inside the board
    def isInside(x, y, N):
        if (x >= 1 and x <= N and
            y >= 1 and y <= N):
            return True
        return False

    # Method returns minimum step to reach
    # target position
    def minStepToReachTarget(knightpos,
                             targetpos, N):

        # all possible movments for the knight
        dx = [2, 2, -2, -2, 1, 1, -1, -1]
        dy = [1, -1, 1, -1, 2, -2, 2, -2]

        queue = []

        # push starting position of knight
        # with 0 distance
        queue.append(cell(knightpos[0], knightpos[1], 0))

        # make all cell unvisited
        visited = [[False for i in range(N + 1)]
                          for j in range(N + 1)]

        # visit starting state
        visited[knightpos[0]][knightpos[1]] = True

        # loop untill we have one element in queue
        while(len(queue) > 0):

            t = queue[0]
            queue.pop(0)

            # if current cell is equal to target
            # cell, return its distance
            if(t.x == targetpos[0] and
               t.y == targetpos[1]):
                return t.dist

            # iterate for all reachable states
            for i in range(8):

                x = t.x + dx[i]
                y = t.y + dy[i]

                if(isInside(x, y, N) and not visited[x][y]):
                    visited[x][y] = True
                    queue.append(cell(x, y, t.dist + 1))

    # Driver Code
    def stepsToPoint(targetX, targetY):
        N = n2
        knightpos = [1, n2]
        targetpos = [targetX, targetY]
        return minStepToReachTarget(knightpos, targetpos, N)

    # for (y, row) in enumerate(dp):
    #     for (x, value) in enumerate(row):
    #         dp[y][x] = (stepsToPoint(x+1,n2-y))


    # for y in range(n2):
    #     for x in range(n2):
    #         if x==n2-1:
    #             print(minStepToReachTarget([1, n2], [x+1,n2-y], n2), end="\n")
    #         else:
    #             print(minStepToReachTarget([1, n2], [x+1,n2-y], n2), end=" ")


    print('\n'.join(' '.join(map(lambda x: str(minStepToReachTarget([1, n2], [x+1, n2-y], n2)), range(n2))) for y in range(n2)))

    # print(*[minStepToReachTarget([1, n2], [x+1,n2-y], n2) for x in range(n2) for y in range(n2)], sep='\n')

    # print("--- %s seconds ---" % (time.time() - start_time))

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

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

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

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

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

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)

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)