Submission details
Task:Robotti
Sender:rene
Submission time:2026-01-17 14:39:17 +0200
Language:Python3 (PyPy3)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#2ACCEPTED0.04 sdetails
#3ACCEPTED0.04 sdetails
#4ACCEPTED0.04 sdetails
#5ACCEPTED0.05 sdetails
#6ACCEPTED0.11 sdetails

Code

import time
square = int(input())
ruudukko = []

robotti_x = 0
robotti_y = -1

def check_if_robot_outside(n, x, y):
    if x > n-1:
        return False
    elif x < 0:
        return False
    elif y > n-1:
        return False
    elif y < 0:
        return False
    else:
        return True

for i in range(square):
    rivi = input()
    riviarray = []
    for i in range(len(rivi)):
        riviarray.append(rivi[i])
    ruudukko.append(riviarray)

# print(square)
# print(ruudukko)

move = True
next_move_left = False
next_move_right = False
next_move_up = False
next_move_down = False
moves = 0
skip = False
robotti_y = -1

last_move = "down"

# print(robotti_x, robotti_y)

while move == True:
    if next_move_left:
        # print("left")
        next_move_left = False
        robotti_x = robotti_x - 1
        move = check_if_robot_outside(square, robotti_x, robotti_y)
        moves = moves + 1
        last_move = "left"
        
        if move == True:
            inspect = ruudukko[robotti_y][robotti_x]

            if inspect == "/":
                next_move_down = True
                ruudukko[robotti_y][robotti_x] = "\\"
                skip = True
            elif inspect == "\\":
                next_move_up = True
                ruudukko[robotti_y][robotti_x] = "/"
                skip = True

            skip = False
            # print(robotti_x, robotti_y)

    elif next_move_right:
        # print("right")
        next_move_right = False
        robotti_x = robotti_x + 1
        move = check_if_robot_outside(square, robotti_x, robotti_y)
        moves = moves + 1
        last_move = "right"

        if move == True:
            inspect = ruudukko[robotti_y][robotti_x]

            if inspect == "/":
                next_move_up = True
                ruudukko[robotti_y][robotti_x] = "\\"
                skip = True
            elif inspect == "\\":
                next_move_down = True
                ruudukko[robotti_y][robotti_x] = "/"
                skip = True

            skip = False
            # print(robotti_x, robotti_y)

    elif next_move_down == True:
        # print("down")
        next_move_down = False
        robotti_y = robotti_y + 1
        move = check_if_robot_outside(square, robotti_x, robotti_y)
        moves = moves + 1
        last_move = "down"

        if move == True:
            inspect = ruudukko[robotti_y][robotti_x]

            if inspect == "/":
                next_move_left = True
                ruudukko[robotti_y][robotti_x] = "\\"
                skip = True
            elif inspect == "\\":
                next_move_right = True
                ruudukko[robotti_y][robotti_x] = "/"
                skip = True

            skip = False
            # print(robotti_x, robotti_y)

    elif next_move_up == True:
        # print("up")
        next_move_up = False
        robotti_y = robotti_y - 1
        move = check_if_robot_outside(square, robotti_x, robotti_y)
        moves = moves + 1
        last_move = "up"
        
        if move == True:
            inspect = ruudukko[robotti_y][robotti_x]

            if inspect == "/":
                next_move_right = True
                ruudukko[robotti_y][robotti_x] = "\\"
                skip = True
            elif inspect == "\\":
                next_move_left = True
                ruudukko[robotti_y][robotti_x] = "/"
                skip = True

            skip = False
            # print(robotti_x, robotti_y)

    else:
        # print("continue")
        if last_move == "down":
            robotti_y = robotti_y + 1
        elif last_move == "up":
            robotti_y = robotti_y - 1
        elif last_move == "right":
            robotti_x = robotti_x + 1
        elif last_move == "left":
            robotti_x = robotti_x - 1
        move = check_if_robot_outside(square, robotti_x, robotti_y)
        moves = moves + 1

        if move == True:
            inspect = ruudukko[robotti_y][robotti_x]

            if inspect == "/":
                if last_move == "down":
                    next_move_left = True
                elif last_move == "up":
                    next_move_right = True
                elif last_move == "right":
                    next_move_up = True
                elif last_move == "left":
                    next_move_down = True
                
                ruudukko[robotti_y][robotti_x] = "\\"
                skip = True
            elif inspect == "\\":
                if last_move == "down":
                    next_move_right = True
                elif last_move == "up":
                    next_move_left = True
                elif last_move == "right":
                    next_move_down = True
                elif last_move == "left":
                    next_move_up = True

                ruudukko[robotti_y][robotti_x] = "/"
                skip = True

            skip = False
            # print(robotti_x, robotti_y)

    # print(ruudukko)

print(moves-1)

Test details

Test 1 (public)

Verdict: ACCEPTED

input
3
./\
\./
\/.

correct output
13

user output
13

Test 2

Verdict: ACCEPTED

input
1
.

correct output
1

user output
1

Test 3

Verdict: ACCEPTED

input
5
./\/\
.....
.....
.....
...

correct output
25

user output
25

Test 4

Verdict: ACCEPTED

input
5
\\/\\
/\/\/
\\/\\
/\/\/
...

correct output
37

user output
37

Test 5

Verdict: ACCEPTED

input
20
\\/\/\/\\./\\.\/\/\.
/\\\\\\/\\\\\\\\\\\.
\\\\\\\\\\\\\\\\\\\\
/\\\\\\\\\\\\\.\\\\\
...

correct output
2519

user output
2519

Test 6

Verdict: ACCEPTED

input
20
\\..................
.\\..............\\.
..\\............\\..
...\\..........\\...
...

correct output
917489

user output
917489