Submission #38674246


Source Code Expand

Copy
use proconio::{input, marker::Chars};
fn main() {
input! {
_n: usize,
mut s: Chars,
};
let mut stack = vec![];
let mut t = vec![];
for (i, s_i) in s.iter().copied().enumerate() {
match s_i {
'(' => {
stack.push(i);
}
')' => {
stack.pop();
}
_ => unreachable!(),
}
t.push(s_i);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
use proconio::{input, marker::Chars};

fn main() {
    input! {
        _n: usize,
        mut s: Chars,
    };

    let mut stack = vec![];
    let mut t = vec![];
    for (i, s_i) in s.iter().copied().enumerate() {
        match s_i {
            '(' => {
                stack.push(i);
            }
            ')' => {
                stack.pop();
            }
            _ => unreachable!(),
        }
        t.push(s_i);
    }
    while let Some(_) = stack.pop() {
        t.push(')');
    }
    t.reverse();
    s = t
        .into_iter()
        .map(|t_i| match t_i {
            '(' => ')',
            ')' => '(',
            _ => unreachable!(),
        })
        .collect::<Vec<char>>();
    let mut t = vec![];
    for (i, s_i) in s.iter().copied().enumerate() {
        match s_i {
            '(' => {
                stack.push(i);
            }
            ')' => {
                stack.pop();
            }
            _ => unreachable!(),
        }
        t.push(s_i);
    }
    while let Some(_) = stack.pop() {
        t.push(')');
    }
    t.reverse();
    let ans = t
        .into_iter()
        .map(|t_i| match t_i {
            '(' => ')',
            ')' => '(',
            _ => unreachable!(),
        })
        .collect::<String>();
    println!("{}", ans);
}

Submission Info

Submission Time
Task D - Insertion
User bouzuya
Language Rust (1.42.0)
Score 400
Code Size 1301 Byte
Status AC
Exec Time 2 ms
Memory 2100 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 12
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All in1.txt, in2.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
in1.txt AC 1 ms 1988 KB
in2.txt AC 1 ms 2040 KB
in3.txt AC 2 ms 2024 KB
in4.txt AC 1 ms 1892 KB
in5.txt AC 2 ms 1992 KB
in6.txt AC 1 ms 1904 KB
in7.txt AC 1 ms 2004 KB
in8.txt AC 1 ms 2100 KB
in9.txt AC 2 ms 1896 KB
s1.txt AC 1 ms 2036 KB
s2.txt AC 2 ms 2008 KB
s3.txt AC 1 ms 2080 KB


2025-04-08 (Tue)
21:17:05 +00:00