結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
ta60143
|
| 提出日時 | 2019-03-12 17:21:03 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,236 bytes |
| コンパイル時間 | 12,021 ms |
| コンパイル使用メモリ | 384,132 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-23 15:47:01 |
| 合計ジャッジ時間 | 13,150 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 WA * 6 |
ソースコード
fn main() {
let vec: Vec<usize> = read_vec();
let index = vec[1];
let text: String = read();
let mut chars: Vec<char> = text.chars().collect();
let mut ans = hoge(index, chars.clone());
if ans == 0 {
chars.reverse();
ans = vec[0] - hoge(index, chars);
}
println!("{}", ans);
}
fn hoge(index: usize, chars: Vec<char>) -> usize {
let mut counter = 0;
for i in 0..index {
match chars[i] {
'(' => { counter += 1; },
')' => { counter -= 1; },
_ => {},
}
}
let registor = counter;
for i in index..chars.len() {
match chars[i] {
'(' => { counter += 1; },
')' => { counter -= 1; },
_ => {},
}
if counter == registor - 1 {
return i + 1;
}
}
return 0;
}
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()
}
ta60143