結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-16 14:35:37 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 963 bytes |
| コンパイル時間 | 11,954 ms |
| コンパイル使用メモリ | 379,488 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:46:38 |
| 合計ジャッジ時間 | 12,850 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
fn read<T: std::str::FromStr>() -> T {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
s.trim()
.split_whitespace()
.map(|e| e.parse().ok().unwrap())
.collect()
}
fn main() {
let input1: Vec<usize> = read_vec();
let input2: String = read();
let mut pairs: Vec<Option<usize>> = vec![None; input1[0]];
use std::collections::VecDeque;
let mut opend_at_queue = VecDeque::new();
let chars = input2.chars().collect::<Vec<char>>();
for i in 0..chars.len() {
if chars[i] == '(' {
opend_at_queue.push_back(i)
} else {
let opend_at = opend_at_queue.pop_back().unwrap();
pairs[opend_at] = Some(i);
pairs[i] = Some(opend_at);
}
}
let ans = pairs[input1[1]-1].unwrap() + 1;
println!("{}", ans)
}