CSES - Datatähti 2023 alku - Results
Submission details
Task:Lehmät
Sender:fait
Submission time:2022-10-31 19:53:13 +0200
Language:Rust
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED28
#2ACCEPTED72
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2details
#2ACCEPTED0.00 s1, 2details
#3ACCEPTED0.00 s1, 2details
#4ACCEPTED0.00 s1, 2details
#5ACCEPTED0.00 s1, 2details
#6ACCEPTED0.00 s2details
#7ACCEPTED0.00 s2details
#8ACCEPTED0.00 s2details
#9ACCEPTED0.00 s2details

Compiler report

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

warning: 1 warning emitted

Code

#[inline]
fn min(a: usize, b: usize) -> usize {
    if a < b {
        return a;
    }
    return b;
}

#[inline]
fn max(a: usize, b: usize) -> usize {
    if a > b {
        return a;
    }
    return b;
}

fn main() {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    let nm: Vec<&str> = buffer.trim().split(' ').collect();
    let n = nm[0].parse::<i32>().unwrap();
    let m = nm[1].parse::<i32>().unwrap();
    let mut cows: Vec<Vec<char>> = Vec::new();
    let mut count: usize = 0;
    for _ in 0..n {
        let mut buffer_t = String::new();
        std::io::stdin().read_line(&mut buffer_t).unwrap();
        count += buffer_t.matches('@').count();
        cows.push(buffer_t.trim().chars().collect());
    }
    let mut inside: bool = false;
    for j in 0..cows.len() {
        for k in 0..cows[j].len() {
            if cows[j][k] == '*' {
                if k == 0 && cows[j][k + 1] != '*' {
                    inside = true;
                } else if cows[j][min(k + 1, cows[j].len() - 1)] != '*' && cows[j][max(if k > 0 { k - 1 } else { 0 }, 0)] != '*' {
                    inside = !inside;
                }
            }
            if cows[j][k] == '@' && !inside {
                count -= 1_usize;
                cows[j][k] = 'C';
            }
        }
    }
    println!("{}", count);
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

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

correct output
0

user output
0

Test 2

Group: 1, 2

Verdict: ACCEPTED

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

correct output
1

user output
1

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: ACCEPTED

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

correct output
64

user output
64

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