結果
問題 | No.22 括弧の対応 |
ユーザー |
|
提出日時 | 2024-07-30 10:04:16 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 700 bytes |
コンパイル時間 | 13,148 ms |
コンパイル使用メモリ | 389,700 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-30 10:04:30 |
合計ジャッジ時間 | 13,594 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
コンパイルメッセージ
warning: unused variable: `n` --> src/main.rs:5:9 | 5 | n: u64, | ^ help: if this is intentional, prefix it with an underscore: `_n` | = note: `#[warn(unused_variables)]` on by default
ソースコード
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);}}