CSES - Datatähti 2021 alku - Results
Submission details
Task:Ratsun reitit
Sender:Sartec
Submission time:2020-10-02 10:39:19 +0300
Language:Python3 (CPython3)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.02 s1, 2, 3details
#20.02 s1, 2, 3details
#30.02 s1, 2, 3details
#40.02 s1, 2, 3details
#50.02 s1, 2, 3details
#60.02 s1, 2, 3details
#70.02 s1, 2, 3details
#80.02 s2, 3details
#90.02 s2, 3details
#100.03 s2, 3details
#110.02 s3details
#120.02 s3details
#130.03 s3details

Code

import time
import numpy
start_time = time.time()
n2 = int(input(""))
dp = [[0 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(*[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:

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 2, in <module>
    import...

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 2, in <module>
    import...

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 2, in <module>
    import...

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 2, in <module>
    import...

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 2, in <module>
    import...

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 2, in <module>
    import...

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 2, in <module>
    import...

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 2, in <module>
    import...

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 2, in <module>
    import...

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 2, in <module>
    import...

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 2, in <module>
    import...

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 2, in <module>
    import...

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 2, in <module>
    import...