Task: | Robotti |
Sender: | Kivvil |
Submission time: | 2024-11-01 16:04:56 +0200 |
Language: | Rust (2021) |
Status: | READY |
Result: | 30 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 30 |
#2 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.00 s | 1, 2 | details |
#2 | ACCEPTED | 0.00 s | 1, 2 | details |
#3 | ACCEPTED | 0.00 s | 1, 2 | details |
#4 | ACCEPTED | 0.00 s | 1, 2 | details |
#5 | ACCEPTED | 0.00 s | 1, 2 | details |
#6 | ACCEPTED | 0.00 s | 1, 2 | details |
#7 | ACCEPTED | 0.00 s | 1, 2 | details |
#8 | ACCEPTED | 0.00 s | 1, 2 | details |
#9 | ACCEPTED | 0.00 s | 1, 2 | details |
#10 | ACCEPTED | 0.00 s | 1, 2 | details |
#11 | ACCEPTED | 0.00 s | 1, 2 | details |
#12 | ACCEPTED | 0.01 s | 2 | details |
#13 | ACCEPTED | 0.01 s | 2 | details |
#14 | ACCEPTED | 0.02 s | 2 | details |
#15 | ACCEPTED | 0.04 s | 2 | details |
#16 | ACCEPTED | 0.04 s | 2 | details |
#17 | ACCEPTED | 0.00 s | 2 | details |
#18 | ACCEPTED | 0.79 s | 2 | details |
#19 | TIME LIMIT EXCEEDED | -- | 2 | details |
#20 | ACCEPTED | 0.00 s | 2 | details |
#21 | ACCEPTED | 0.00 s | 2 | details |
#22 | ACCEPTED | 0.42 s | 2 | details |
#23 | TIME LIMIT EXCEEDED | -- | 2 | details |
#24 | TIME LIMIT EXCEEDED | -- | 2 | details |
Compiler report
warning: method `tulosta_huoneet` is never used --> input/code.rs:131:8 | 26 | impl Rakennus { | ------------- method in this implementation ... 131 | fn tulosta_huoneet(&self) { | ^^^^^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: 1 warning emitted
Code
use std::vec::Vec; fn main() { let mut stdin_lines = std::io::stdin().lines(); // Luetaan vain kartta huoneista, ei tarvita ensimmäistä riviä, joten skipataan se. let _ = stdin_lines.next(); let rivi = stdin_lines.next().unwrap().unwrap(); let mut rakennus = Rakennus::new(rivi); let (askeleet, kolikot) = rakennus.pelaa(); println!("{} {}", askeleet, kolikot); } struct Rakennus { // Kartta rakennuksen huoneista huoneet: Vec<Huone>, // Indeksi huoneet-vektoriin, jossa robotti sijaitsee robotti_indeksi: usize, keratyt_kolikot: u32, askeleet: u32, } impl Rakennus { fn new(syote: String) -> Self { Self { huoneet: syote .chars() .map(|merkki| Huone::from_char(merkki)) .collect(), robotti_indeksi: syote.find("R").unwrap(), keratyt_kolikot: 0, askeleet: 0, } } // Pelaa peliä. Palauttaa tuplen, jossa ensimmäinen askelten määrä ja toinen kerättyjen // kolikoiden määrä fn pelaa(&mut self) -> (u32, u32) { // self.tulosta_huoneet(); self.pelaa_inner(); (self.askeleet, self.keratyt_kolikot) } // Funktio, joka pelaa peliä yksi kolikon keräys kerrallaan fn pelaa_inner(&mut self) { loop { let lahin_kolikko = match self.etsi_lahin_kolikko() { Some(kolikko) => kolikko, None => { return; } }; self.askeleet += (self.robotti_indeksi as i32 - lahin_kolikko as i32).abs() as u32; self.keratyt_kolikot += 1; self.robotti_indeksi = lahin_kolikko; self.huoneet[lahin_kolikko] = Huone::Tyhja; // self.tulosta_huoneet(); } } fn etsi_lahin_kolikko(&self) -> Option<usize> { let kolikko_vasemmalla = self.etsi_kolikko_vasemmalla(); let kolikko_oikealla = self.etsi_kolikko_oikealla(); if let None = kolikko_vasemmalla { return kolikko_oikealla; } if let None = kolikko_oikealla { return kolikko_vasemmalla; } let kolikko_vasemmalla = kolikko_vasemmalla.unwrap(); let kolikko_oikealla = kolikko_oikealla.unwrap(); let etaisyys_vasemmalle = self.robotti_indeksi - kolikko_vasemmalla; let etaisyys_oikealle = kolikko_oikealla - self.robotti_indeksi; if etaisyys_vasemmalle > etaisyys_oikealle { Some(kolikko_oikealla) } else if etaisyys_oikealle > etaisyys_vasemmalle { Some(kolikko_vasemmalla) } else { None } } fn etsi_kolikko_oikealla(&self) -> Option<usize> { // let mut i: usize = self.robotti_indeksi; // loop { // if i >= self.huoneet.len() - 1 { // return None; // } // i += 1; // if self.huoneet[i] == Huone::Kolikko { // return Some(i); // } // } match self.huoneet[self.robotti_indeksi..self.huoneet.len()] .iter() .position(|huone| *huone == Huone::Kolikko) { Some(p) => Some(p + self.robotti_indeksi), None => None, } } fn etsi_kolikko_vasemmalla(&self) -> Option<usize> { // let mut i: usize = self.robotti_indeksi; // loop { // if i <= 0 { // return None; // } // i -= 1; // if self.huoneet[i] == Huone::Kolikko { // return Some(i); // } // } match self.huoneet[0..=self.robotti_indeksi] .iter() .rev() .position(|huone| *huone == Huone::Kolikko) { Some(p) => Some(self.robotti_indeksi - p), None => None, } } fn tulosta_huoneet(&self) { let mut string = self .huoneet .iter() .map(|huone| match huone { Huone::Tyhja => ".", Huone::Kolikko => "*", }) .collect::<String>(); string.replace_range(self.robotti_indeksi..self.robotti_indeksi + 1, "R"); println!("Huoneet: {}", string); } } #[derive(PartialEq, Eq)] enum Huone { Tyhja, Kolikko, } impl Huone { fn from_char(character: char) -> Self { match character { '*' => Huone::Kolikko, '.' => Huone::Tyhja, 'R' => Huone::Tyhja, _ => panic!("Viallinen merkki stdin:ssa"), } } }
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1 R |
correct output |
---|
0 0 |
user output |
---|
0 0 |
Test 2
Group: 1, 2
Verdict: ACCEPTED
input |
---|
10 ...R...... |
correct output |
---|
0 0 |
user output |
---|
0 0 |
Test 3
Group: 1, 2
Verdict: ACCEPTED
input |
---|
10 **.R...*** |
correct output |
---|
12 5 |
user output |
---|
12 5 |
Test 4
Group: 1, 2
Verdict: ACCEPTED
input |
---|
10 ***R****** |
correct output |
---|
0 0 |
user output |
---|
0 0 |
Test 5
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 R................................ |
correct output |
---|
947 9 |
user output |
---|
947 9 |
Test 6
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 ................................. |
correct output |
---|
886 9 |
user output |
---|
886 9 |
Test 7
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 .....*..*....**..**..*......*.... |
correct output |
---|
1287 400 |
user output |
---|
1287 400 |
Test 8
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 ************.*****************... |
correct output |
---|
0 0 |
user output |
---|
0 0 |
Test 9
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 ******************************... |
correct output |
---|
0 0 |
user output |
---|
0 0 |
Test 10
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 R*****************************... |
correct output |
---|
999 999 |
user output |
---|
999 999 |
Test 11
Group: 1, 2
Verdict: ACCEPTED
input |
---|
1000 ******************************... |
correct output |
---|
999 999 |
user output |
---|
999 999 |
Test 12
Group: 2
Verdict: ACCEPTED
input |
---|
10000 .......**........*...........*... |
correct output |
---|
10971 999 |
user output |
---|
10971 999 |
Test 13
Group: 2
Verdict: ACCEPTED
input |
---|
10000 *..*....*......*.....*..*........ |
correct output |
---|
9999 999 |
user output |
---|
9999 999 |
Test 14
Group: 2
Verdict: ACCEPTED
input |
---|
10000 *.*.*...**.*...*....**.**.**..... |
correct output |
---|
18766 5000 |
user output |
---|
18766 5000 |
Test 15
Group: 2
Verdict: ACCEPTED
input |
---|
10000 R*****************************... |
correct output |
---|
9999 9999 |
user output |
---|
9999 9999 |
Test 16
Group: 2
Verdict: ACCEPTED
input |
---|
10000 ******************************... |
correct output |
---|
9999 9999 |
user output |
---|
9999 9999 |
Test 17
Group: 2
Verdict: ACCEPTED
input |
---|
200000 ................................. |
correct output |
---|
0 0 |
user output |
---|
0 0 |
Test 18
Group: 2
Verdict: ACCEPTED
input |
---|
200000 ................................. |
correct output |
---|
299934 10000 |
user output |
---|
299934 10000 |
Test 19
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
200000 **.***....**..**.....***.*..*.... |
correct output |
---|
299998 100000 |
user output |
---|
(empty) |
Test 20
Group: 2
Verdict: ACCEPTED
input |
---|
200000 ******************************... |
correct output |
---|
0 0 |
user output |
---|
0 0 |
Test 21
Group: 2
Verdict: ACCEPTED
input |
---|
200000 R................................ |
correct output |
---|
133765 3 |
user output |
---|
133765 3 |
Test 22
Group: 2
Verdict: ACCEPTED
input |
---|
200000 R................................ |
correct output |
---|
199982 5000 |
user output |
---|
199982 5000 |
Test 23
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
200000 R*****************************... |
correct output |
---|
199999 199999 |
user output |
---|
(empty) |
Test 24
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
200000 ******************************... |
correct output |
---|
199999 199999 |
user output |
---|
(empty) |