結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
ユーザー pia019
提出日時 2025-05-16 21:56:08
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,584 bytes
コンパイル時間 2,850 ms
コンパイル使用メモリ 279,524 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-17 00:26:08
合計ジャッジ時間 5,184 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 48 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include "atcoder/fenwicktree"
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
const ll MOD = 998244353;
const double INFD = 1.0E18;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
//const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using Pair = pair<ll, ll>;
using Graph = vector<vector<pair<int, int>>>;



int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int n, k; cin >> n >> k;
    string s; cin >> s;
    //最低の値、n/2葉
    bool ok = true;
    int cnt = 0;
    int m = n / 2;
    bool be = true;
    for (int i = 0; i < n; i++){
        if (s[i] == '(') cnt++;
        else cnt--;
        if (cnt < 0) ok = false;
        if (i != n - 1 && cnt == 0) be = false;
        if (i > 0 && s[i - 1] == '(' && s[i] == ')') m++;
    }
    if (cnt != 0) ok = false;
    if (k < m || (k == m && be)) ok = false;
    cout << (ok ? "Yes" : "No") << endl;
    if (ok){
        bool begin = true;
        string ans;
        for (int i = 0; i < n; i++){
            if (s[i] == '(') ans += "(";
            else{
                if (i > 0 && s[i - 1] == '('){
                    ans += "1+1";
                }
                else{
                    ans += "1";
                }
                ans += ")";
                if (i != n - 1) ans += "+";
            }
        }
        for (int j = 0; j < k - m; j++) ans += "+1";
        cout << ans << endl;
    }
    
    return 0;
}
0