Submission details
Task:Robotti
Sender:JuusoH
Submission time:2026-01-17 13:32:20 +0200
Language:Rust (2021)
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#50.00 sdetails
#60.01 sdetails

Compiler report

warning: unused variable: `i`
 --> input/code.rs:8:9
  |
8 |     for i in 0..n {
  |         ^ help: if this is intentional, prefix it with an underscore: `_i`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

Code

use std::io::stdin;
fn main() {
    let stdin = stdin();
    let mut input = String::new();
    _ = stdin.read_line(&mut input);
    let n: usize = input.trim().parse().unwrap();
    let mut board = vec![];
    for i in 0..n {
        input.clear();
        let mut row = vec![];
        _ = stdin.read_line(&mut input);
        let cells = input.trim().chars();
        for a in cells {
            let mut c = Cell::Dot;
            if a == '/' {
                c = Cell::FSlash
            } else if a == '\\' {
                c = Cell::BSlash
            }
            row.push(c);
        }
        board.push(row);
    }
    //println!("{board:?}");
    let (mut rx, mut ry) = (0i32, 0i32);
    let mut dir = (0, 1);
    let mut iteration = 0;
    while ry < n as i32 {
        if rx == board.len() as i32 {
            break;
        }
        let c = board[ry as usize][rx as usize];
        board[ry as usize][rx as usize] = rotate(c);
        dir = new_dir(c, dir);
        rx += dir.0;
        ry += dir.1;

        iteration += 1;
    }
    println!("{iteration}");
}

fn new_dir(cell: Cell, dir: (i32, i32)) -> (i32, i32) {
    match cell {
        Cell::Dot => dir,
        Cell::BSlash => (dir.1, dir.0),
        Cell::FSlash => (-dir.1, -dir.0),
    }
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Cell {
    Dot,
    FSlash,
    BSlash,
}
fn rotate(cell: Cell) -> Cell {
    if cell == Cell::Dot {
        return cell;
    } else {
        if cell == Cell::BSlash {
            return Cell::FSlash;
        }
        return Cell::BSlash;
    }
}

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:

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

correct output
2519

user output
(empty)

Error:
thread 'main' panicked at input/code.rs:32:35:
index out of bounds: the len is 20 but the index is 18446744073709551615
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Test 6

Verdict:

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

correct output
917489

user output
(empty)

Error:
thread 'main' panicked at input/code.rs:32:22:
index out of bounds: the len is 20 but the index is 18446744073709551615
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace