CSES - Putka Open 2020 – 2/5 - Results
Submission details
Task:Kortit
Sender:Hennkka
Submission time:2020-09-26 11:23:20 +0300
Language:Rust
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED23
#2ACCEPTED77
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s2details

Compiler report

warning: unused variable: `n`
  --> input/code.rs:33:13
   |
33 |         let n: usize = lines.next().unwrap().unwrap().parse().unwrap();
   |             ^ help: consider prefixing with an underscore: `_n`
   |
   = note: `#[warn(unused_variables)]` on by default

Code

use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::io::BufRead;

fn solve(my: Vec<usize>) -> usize {
    let n = my.len() * 2;
    let my: BTreeSet<_> = my.into_iter().collect();
    let mut other = VecDeque::new();
    for i in 1..=n {
        if !my.contains(&i) {
            other.push_front(i);
        }
    }
    let mut my: VecDeque<_> = my.into_iter().collect();
    let mut points = 0;
    for o in other {
        if *my.back().unwrap() > o {
            my.pop_back();
            points += 1;
        } else {
            my.pop_front();
        }
    }
    points
}

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 n: usize = lines.next().unwrap().unwrap().parse().unwrap();
        let v = lines
            .next()
            .unwrap()
            .unwrap()
            .split_whitespace()
            .map(|v| v.parse().unwrap())
            .collect();
        println!("{}", solve(v));
    }
}

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

    #[test]
    fn test_samples() {
        assert_eq!(solve(vec![2, 4, 5]), 2);
        assert_eq!(solve(vec![1]), 0);
        assert_eq!(solve(vec![1, 3]), 1);
    }
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
1000
2
1
6
2 4 5
...

correct output
0
2
0
2
1
...

user output
0
2
0
2
1
...
Truncated

Test 2

Group: 2

Verdict: ACCEPTED

input
1000
70
56 23 58 70 2 57 27 61 47 3 42...

correct output
30
15
1
38
29
...

user output
30
15
1
38
29
...
Truncated