結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-10 04:38:57 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 597 ms / 5,000 ms |
| コード長 | 1,444 bytes |
| コンパイル時間 | 13,223 ms |
| コンパイル使用メモリ | 395,472 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-14 10:41:23 |
| 合計ジャッジ時間 | 17,603 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#[macro_export]
macro_rules! setup {
{ mut $input:ident: SplitWhitespace $(,)? } => {
use std::io::Read;
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).unwrap();
let mut $input = buf.split_whitespace();
};
}
#[macro_export]
macro_rules! parse_next {
($str_iter:expr) => {
$str_iter.next().unwrap().parse().unwrap()
};
}
use std::collections::HashMap;
fn main() {
setup! { mut input: SplitWhitespace };
let n: usize = parse_next!(input);
let k: usize = parse_next!(input);
let s: String = parse_next!(input);
let cs = s.chars().collect::<Vec<_>>();
let mut corr = HashMap::new();
while corr.len() != n {
for i in 0..(n - 1) {
if corr.get(&i).is_some() {
continue;
}
if !(cs[i] == '(') {
continue;
}
let mut matched = false;
for j in (i + 1)..n {
if corr.get(&j).is_some() {
continue;
}
if cs[j] == ')' {
matched = true;
corr.insert(i, j);
corr.insert(j, i);
}
break;
}
if !matched {
continue;
}
break;
}
}
let ans = *corr.get(&(k - 1)).unwrap() + 1;
println!("{}", ans);
}