Skip to content

Commit

Permalink
tessoku-book c17
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Dec 27, 2022
1 parent 0ae15ca commit 52fe0c3
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions tessoku-book/src/bin/c17.rs
@@ -1,10 +1,48 @@
use proconio::{input, marker::Usize1};
use std::collections::VecDeque;

use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
q: usize,
};
let ans = n - a.len();
println!("{}", ans);

let mut left = VecDeque::new();
let mut right = VecDeque::new();
for _ in 0..q {
input! {
t: char,
}

match t {
'A' => {
input! {
x: String,
}
right.push_back(x);
if left.len() < right.len() {
left.push_back(right.pop_front().unwrap());
}
}
'B' => {
input! {
x: String,
}
left.push_back(x);
if left.len() > right.len() + 1 {
right.push_front(left.pop_back().unwrap());
}
}
'C' => {
left.pop_front();
if left.len() < right.len() {
left.push_back(right.pop_front().unwrap());
}
}
'D' => {
println!("{}", left.front().unwrap());
}
_ => unreachable!(),
}
}
}

0 comments on commit 52fe0c3

Please sign in to comment.