CSES - Datatähti 2025 alku - Results
Submission details
Task:Robotti
Sender:Ez
Submission time:2024-11-05 12:44:51 +0200
Language:Rust (2021)
Status:COMPILE ERROR

Compiler report

error[E0425]: cannot find value `r` in this scope
  --> input/code.rs:20:28
   |
5  | static mut O: bool = false;
   | --------------------------- similarly named static `O` defined here
...
20 |         OI = t.iter().skip(r).position(|c| *c=='*').unwrap_or(1000000);
   |                            ^ help: a static with a similar name exists: `O`

error[E0425]: cannot find value `r` in this scope
  --> input/code.rs:21:36
   |
5  | static mut O: bool = false;
   | --------------------------- similarly named static `O` defined here
...
21 |         VI = t.iter().rev().skip(n-r-1).position(|c| *c=='*').unwrap_or(1000000)
   |                                    ^ help: a static with a similar name exists: `O`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.

Code

use std::{process::exit, io::{BufRead, BufReader}};
static mut COINS: i32 = 0;
static mut STEPS: usize = 0;
static mut V: bool = false;
static mut O: bool = false;
static mut VI: usize = 0;
static mut OI: usize = 0;

fn main() {
    let mut input = BufReader::new(std::io::stdin());
    let mut line = "".to_string();
    input.read_line(&mut line).unwrap();
    let mut split = line.split_whitespace();
    let n: usize = split.next().unwrap().parse().unwrap();
    let mut robot: usize = 0;
    line = "".to_string();    input.read_line(&mut line).unwrap();
    let mut t: Vec<char> = line.chars().filter(|a| *a=='*'||*a=='.'||*a=='R').collect();
    for i in t.iter().enumerate(){if *i.1=='R'{robot = i.0;}}
    unsafe{
        OI = t.iter().skip(r).position(|c| *c=='*').unwrap_or(1000000);
        VI = t.iter().rev().skip(n-r-1).position(|c| *c=='*').unwrap_or(1000000)
    }
    loop{
    unsafe{robot = step(n, &mut t,robot)}}
}
unsafe fn step(n: usize, t: &mut Vec<char>, r: usize) -> usize{
    t[r]='.';
    let oikea:usize = if O{1000000}else{t.iter().skip(r).position(|c| *c=='*').unwrap_or(1000000)};
    if oikea == 1000000{O=true}
    let vasen:usize = if V{1000000}else{r - t.iter().rev().skip(n-r-1).position(|c| *c=='*').unwrap_or(1000000)};
    if vasen == 1000000{V=true}
    if vasen == oikea ||( vasen>1000000 && oikea>1000000){print!("{} {}",STEPS, COINS); exit(0)}
    if vasen < oikea{ 
        t[vasen]='R';
        STEPS+=r-vasen;
        COINS +=1 ;
        vasen
    }else{
        t[r+oikea]='R';
        STEPS+=oikea;
        COINS +=1 ;
        r+oikea
    }
}