結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-26 06:22:24 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,443 bytes |
| コンパイル時間 | 13,667 ms |
| コンパイル使用メモリ | 377,060 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:42:14 |
| 合計ジャッジ時間 | 14,215 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
use std::io::{self, BufRead};
fn get_lines() -> Vec<String> {
let stdin = io::stdin();
let lines: Vec<String> = stdin.lock().lines().map(|l| l.unwrap()).collect();
return lines;
}
fn main(){
let l = get_lines();
let x: Vec<i32> = l[0].split(' ').map(|x| x.parse::<i32>().unwrap()).collect();
let (n, k) = (x[0], x[1]);
let s = &l[1];
let mut i = k;
let mut r = 1;
if n as f64 / 2.0 >= k as f64 {
let mut x = s.chars();
if x.nth((k - 1) as usize).unwrap() == '(' {
for c in x {
i += 1;
r += if c == '(' { 1 } else { -1 };
if r == 0 { println!("{}", i); return; }
}
} else {
for c in s.chars().rev().skip((n - (k - 1)) as usize) {
i -= 1;
r += if c == ')' { 1 } else { -1 };
if r == 0 { println!("{}", i); return; }
}
}
} else {
let mut x = s.chars().rev();
if x.nth((n - k) as usize).unwrap() == ')' {
for c in x {
i -= 1;
r += if c == ')' { 1 } else { -1 };
if r == 0 { println!("{}", i); return; }
}
} else {
for c in s.chars().skip(k as usize) {
i += 1;
r += if c == '(' { 1 } else { -1 };
if r == 0 { println!("{}", i); return; }
}
}
}
}