use proconio::marker::Chars; fn main() { proconio::input! { n: u64, k: u64, s: Chars, } println!("{}", proc(k, &s)); } fn proc(k: u64, s: &[char]) -> u64 { let mut taiou = vec![0; s.len()]; let mut stack = Vec::new(); for (i, s) in s.iter().enumerate() { match s { '(' => stack.push(i), ')' => { let j = stack.pop().unwrap(); taiou[i] = j; taiou[j] = i; } _ => unreachable!(), } } taiou[k as usize - 1] as u64 + 1 } #[cfg(test)] mod test { use super::*; #[test] fn test() { assert_eq!(proc(2, 5), 3); } }