結果
| 問題 | No.3143 Colorless Green Parentheses Sleep Furiously | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-05-16 21:45:37 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,847 bytes | 
| コンパイル時間 | 11,455 ms | 
| コンパイル使用メモリ | 389,576 KB | 
| 実行使用メモリ | 7,840 KB | 
| 最終ジャッジ日時 | 2025-05-17 00:24:12 | 
| 合計ジャッジ時間 | 14,020 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 47 WA * 2 | 
コンパイルメッセージ
warning: type alias `Map` is never used --> src/main.rs:5:6 | 5 | type Map<K, V> = BTreeMap<K, V>; | ^^^ | = note: `#[warn(dead_code)]` on by default warning: type alias `Set` is never used --> src/main.rs:6:6 | 6 | type Set<T> = BTreeSet<T>; | ^^^ warning: type alias `Deque` is never used --> src/main.rs:7:6 | 7 | type Deque<T> = VecDeque<T>; | ^^^^^ warning: type alias `Heap` is never used --> src/main.rs:8:6 | 8 | type Heap<T> = BinaryHeap<T>; | ^^^^ warning: constant `MOD` is never used --> src/main.rs:10:7 | 10 | const MOD: u64 = 998_244_353; | ^^^
ソースコード
use proconio::marker::*;
use proconio::*;
use std::collections::*;
type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;
type Heap<T> = BinaryHeap<T>;
const MOD: u64 = 998_244_353;
fn main() {
    input! {
        n: usize,
        k: usize,
        s: Bytes,
    }
    // S が対応がとれた括弧列かどうか。
    let mut v = 0;
    for &c in &s {
        if c == b'(' {
            v += 1;
        } else {
            if v == 0 {
                println!("No");
                return;
            } else {
                v -= 1;
            }
        }
    }
    if v != 0 {
        println!("No");
        return;
    }
    // 作ることのできる数字の下界
    let mut x = n / 2;
    for i in 0..n - 1 {
        if s[i] == b'(' && s[i + 1] == b')' {
            x += 1;
        }
    }
    if x <= k {
        println!("Yes");
        let mut ans = vec![];
        for &c in &s {
            if c == b'(' {
                if ans.is_empty() || ans.last().unwrap() == &'(' {
                    ans.push('(');
                } else {
                    ans.push('+');
                    ans.push('(');
                }
            } else {
                if ans.last().unwrap() == &'(' {
                    ans.push('1');
                    ans.push('+');
                    ans.push('1');
                    ans.push(')');
                } else {
                    ans.push('+');
                    ans.push('1');
                    ans.push(')');
                }
            }
        }
        for _ in 0..k - x {
            ans.push('+');
            ans.push('1');
        }
        println!(
            "{}",
            ans.iter()
                .fold("".to_string(), |acc, a| acc + &a.to_string())
        );
    } else {
        println!("No");
    }
}
            
            
            
        