CSES - Datatähti 2021 alku - Results
Submission details
Task:Ratsun reitit
Sender:Microwave Abuser
Submission time:2020-09-29 15:15:38 +0300
Language:CPython3
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED27
#2ACCEPTED31
#3ACCEPTED42
Test results
testverdicttimegroup
#1ACCEPTED0.02 s1, 2, 3details
#2ACCEPTED0.02 s1, 2, 3details
#3ACCEPTED0.03 s1, 2, 3details
#4ACCEPTED0.02 s1, 2, 3details
#5ACCEPTED0.03 s1, 2, 3details
#6ACCEPTED0.02 s1, 2, 3details
#7ACCEPTED0.03 s1, 2, 3details
#8ACCEPTED0.03 s2, 3details
#9ACCEPTED0.05 s2, 3details
#10ACCEPTED0.05 s2, 3details
#11ACCEPTED0.07 s3details
#12ACCEPTED0.11 s3details
#13ACCEPTED0.11 s3details

Code

class Position:
    def __init__(self, x, y):
        self.x = x
        self.y = y

class Board:
    def __init__(self, n):
        self.boardArray = [[0 for i in range(n)] for j in range(n)]
        self.boardSize = n

    def tulosta(self):
        for rivi in self.boardArray:
            strinki = ""
            for sarake in rivi:
                strinki += str(sarake) + " "
            print(strinki[:-1])


    def getSquareValue(self, pos):
        return self.boardArray[pos.x][pos.y]

    def setSquareValue(self, pos, value):
        self.boardArray[pos.x][pos.y] = value

    def iterateKnight(self, positionList):
        nextPositionList = []

        for curPos in positionList:
            curVal = self.getSquareValue(curPos)
            hMoves = []
            hMoves.append(Position(curPos.x+1, curPos.y-2)) #hMoves = hypoteettinen siirto, top to clockwise
            hMoves.append(Position(curPos.x+2, curPos.y-1))
            hMoves.append(Position(curPos.x+2, curPos.y+1))
            hMoves.append(Position(curPos.x+1, curPos.y+2))
            hMoves.append(Position(curPos.x-1, curPos.y+2))
            hMoves.append(Position(curPos.x-2, curPos.y+1))
            hMoves.append(Position(curPos.x-2, curPos.y-1))
            hMoves.append(Position(curPos.x-1, curPos.y-2))

            for move in hMoves:
                if (move.x >= 0) and (move.x < self.boardSize) and (move.y >= 0) and (move.y < self.boardSize):
                    #jos move osoittautuu lailliseksi
                    if self.getSquareValue(move) == 0:
                        #jos on vielä 0
                        self.setSquareValue(move, curVal + 1)
                        nextPositionList.append(move)

        if nextPositionList:    #lista ei ole tyhjä = on vielä iteroitavaa
            self.iterateKnight(nextPositionList)

        return


def main():
    n = int(input())
    board = Board(n)
    board.iterateKnight([Position(0, 0)]);
    board.setSquareValue(Position(0, 0), 0)
    board.tulosta()

main()

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

input
75

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 12

Group: 3

Verdict: ACCEPTED

input
99

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 13

Group: 3

Verdict: ACCEPTED

input
100

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