CSES - Datatähti 2023 alku - Results
Submission details
Task:Lehmät
Sender:Mixu_78
Submission time:2022-11-05 22:21:56 +0200
Language:Rust
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.00 s1, 2details
#20.00 s1, 2details
#30.00 s1, 2details
#40.00 s1, 2details
#50.00 s1, 2details
#60.00 s2details
#70.00 s2details
#80.00 s2details
#90.00 s2details

Compiler report

warning: unused variable: `m`
  --> input/code.rs:11:9
   |
11 |     let m: usize = split.next().unwrap().parse().unwrap();
   |         ^ help: if this is intentional, prefix it with an underscore: `_m`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `map`
  --> input/code.rs:13:13
   |
13 |     let mut map: Vec<String> = Vec::with_capacity(n);
   |             ^^^ help: if this is intentional, prefix it with an underscore: `_map`

warning: variable does not need to be mutable
  --> input/code.rs:13:9
   |
13 |     let mut map: Vec<String> = Vec::with_capacity(n);
   |         ----^^^
   |         |
   |         help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

warning: 3 warnings emitted

Code

use std::io::{self, BufReader, BufRead};

fn main() {
    let stdin = io::stdin();
    let buf = BufReader::new(stdin);
    let mut lines = buf.lines();
    let dim = lines.next().unwrap().unwrap();
    let mut split = dim.split(" ");

    let n: usize = split.next().unwrap().parse().unwrap();
    let m: usize = split.next().unwrap().parse().unwrap();

    let mut map: Vec<String> = Vec::with_capacity(n);
    let mut start: (usize, usize) = (0, 0);
    let mut end: (usize, usize) = (0, 0);
    let mut cows = 0;

    for y in 0..n {
        let line = lines.next().unwrap().unwrap();
        if start == (0, 0) {
            if let Some(x) = line.find('*') {
                start = (y, x);
                end = (n, line.rfind('*').unwrap())
            }
        } else {
            if y > start.0 || y > end.0 {
                if line.find('*').is_none() {
                    end = (y - 1, end.1);
                    continue;
                }

                cows += line
                    .chars()
                    .enumerate()
                    .fold(0, |acc, (i, c)| if i > start.1 && i < end.1 && c == '@' { acc + 1 } else { acc + 0 });
            }
        }
    }

    println!("{start:?}, {end:?}, {cows}")
}

Test details

Test 1

Group: 1, 2

Verdict:

input
3 3
***
*.*
***

correct output
0

user output
(1, 0), (3, 2), 0

Test 2

Group: 1, 2

Verdict:

input
3 3
***
*@*
***

correct output
1

user output
(1, 0), (3, 2), 0

Test 3

Group: 1, 2

Verdict:

input
5 10
...@......
..******..
@.*@@@@*.@
..******..
...

correct output
4

user output
(1, 2), (3, 7), 4

Test 4

Group: 1, 2

Verdict:

input
10 10
@@...@.@@@
..@@.@@..@
@.*******@
..*@....*.
...

correct output
11

user output
(2, 2), (8, 8), 11

Test 5

Group: 1, 2

Verdict:

input
10 10
**********
*@@@@@@@@*
*@@@@@@@@*
*@@@@@@@@*
...

correct output
64

user output
(1, 0), (10, 9), 56

Test 6

Group: 2

Verdict:

input
100 100
.........................@.......

correct output
60

user output
(6, 10), (98, 91), 60

Test 7

Group: 2

Verdict:

input
100 100
..@@..........@......@....@@.....

correct output
1507

user output
(9, 5), (98, 94), 1507

Test 8

Group: 2

Verdict:

input
100 100
.@..@@..@@.@..@..@..@@..@..@.....

correct output
3348

user output
(10, 9), (98, 94), 3348

Test 9

Group: 2

Verdict:

input
100 100
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...

correct output
7225

user output
(8, 5), (98, 91), 7225