CSES - Datatähti 2023 alku - Results
Submission details
Task:Lehmät
Sender:Mixu_78
Submission time:2022-11-05 22:22:48 +0200
Language:Rust
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2details
#20.00 s1, 2details
#3ACCEPTED0.00 s1, 2details
#4ACCEPTED0.00 s1, 2details
#50.00 s1, 2details
#6ACCEPTED0.00 s2details
#7ACCEPTED0.00 s2details
#8ACCEPTED0.00 s2details
#9ACCEPTED0.00 s2details

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 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!("{cows}")
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

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

correct output
0

user output
0

Test 2

Group: 1, 2

Verdict:

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

correct output
1

user output
0

Test 3

Group: 1, 2

Verdict: ACCEPTED

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

correct output
4

user output
4

Test 4

Group: 1, 2

Verdict: ACCEPTED

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

correct output
11

user output
11

Test 5

Group: 1, 2

Verdict:

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

correct output
64

user output
56

Test 6

Group: 2

Verdict: ACCEPTED

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

correct output
60

user output
60

Test 7

Group: 2

Verdict: ACCEPTED

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

correct output
1507

user output
1507

Test 8

Group: 2

Verdict: ACCEPTED

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

correct output
3348

user output
3348

Test 9

Group: 2

Verdict: ACCEPTED

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

correct output
7225

user output
7225