結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
コンテスト
ユーザー あるふぁ
提出日時 2026-08-27 22:06:06
言語 Rust
(1.97.1 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
WA  
実行時間 -
コード長 802 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 738 ms
コンパイル使用メモリ 185,088 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-27 22:07:24
合計ジャッジ時間 5,383 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use proconio::{input, marker::Chars};

fn main(){
    input!{
        n: usize,
        k: usize,
        s: Chars,
    }

    let mut ans = String::new();
    let mut ls = Vec::<usize>::new();
    let mut ns: usize = 0;
    for (i, &c) in s.iter().enumerate(){
        ans.push(c);
        if c == '('{
            ls.push(i);
            if i < n-1 && s[i+1] == ')'{
                ans.push_str("1+1");
                ns += 2;
            }else{
                ans.push_str("1+");
                ns += 1
            }
        }else{
            ans.push('+');
            ls.pop();
        }
    }

    ans.pop();
    while ns < k{
        ans.push_str("+1");
        ns += 1;
    }

    if ns > k{
        println!("No");
    }else{
        println!("Yes");
        println!("{}", ans);
    }
}
0