CSES - Putka Open 2020 – 4/5 - Results
Submission details
Task:Peli
Sender:Hennkka
Submission time:2020-11-06 21:23:52 +0200
Language:Rust
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED35
#2ACCEPTED65
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s2details

Compiler report

warning: unused imports: `HashMap`, `VecDeque`
 --> input/code.rs:1:24
  |
1 | use std::collections::{HashMap, VecDeque};
  |                        ^^^^^^^  ^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

Code

use std::collections::{HashMap, VecDeque};
use std::io::BufRead;

fn solve(a: usize, b: usize, n: usize) -> usize {
    let (a, b) = if a < b { (a, b) } else { (b, a) };
    let rounds_till_left = a + b - 1;
    let rounds_till_right = n - 1 - b + n - 2 - a;
    assert_eq!(rounds_till_left % 2, rounds_till_right % 2);
    if rounds_till_left % 2 == 1 || rounds_till_right % 2 == 1 {
        1
    } else {
        2
    }
}

fn main() {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let mut lines = stdin.lines();

    let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
    for _ in 0..t {
        let l: String = lines.next().unwrap().unwrap();
        let mut a = None;
        let mut b = None;
        for (i, c) in l.chars().enumerate() {
            if c == 'P' {
                if a == None {
                    a = Some(i);
                } else {
                    b = Some(i);
                }
            }
        }
        println!("{}", solve(a.unwrap(), b.unwrap(), l.len()));
    }
}

#[cfg(test)]
mod tests {
    use super::*;
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
100
PP.
P......P.
.PP
..P.P.
...

correct output
2
2
2
1
2
...

user output
2
2
2
1
2
...
Truncated

Test 2

Group: 2

Verdict: ACCEPTED

input
100
.................................

correct output
2
1
2
1
1
...

user output
2
1
2
1
1
...
Truncated