結果
| 問題 | No.22 括弧の対応 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-26 06:25:01 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 1,427 bytes |
| コンパイル時間 | 11,642 ms |
| コンパイル使用メモリ | 379,152 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:42:47 |
| 合計ジャッジ時間 | 12,590 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 / 2 >= k {
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; }
}
}
}
}