結果

問題 No.22 括弧の対応
ユーザー tonyu0
提出日時 2019-12-06 23:49:42
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 729 bytes
コンパイル時間 12,626 ms
コンパイル使用メモリ 395,916 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 07:46:17
合計ジャッジ時間 13,642 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn main() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let s: Vec<char> = itr.next().unwrap().chars().collect();

    let mut stack = Vec::new();
    for i in 0..n {
        if s[i] == '(' {
            stack.push(i);
        } else {
            let res = stack.pop().unwrap() + 1;
            if i + 1 == k {
                println!("{}", res);
                return;
            }
            if res == k {
                println!("{}", i + 1);
                return;
            }
        }
    }
}
0