結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
ユーザー flippergo
提出日時 2025-07-02 10:09:41
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,522 bytes
コンパイル時間 970 ms
コンパイル使用メモリ 82,556 KB
実行使用メモリ 166,628 KB
最終ジャッジ日時 2025-07-02 10:09:53
合計ジャッジ時間 10,400 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43 RE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K = map(int,input().split())
S = input().strip()
A = []
flag = True
for i in range(N):
    if S[i]=="(":
        A.append(S[i])
    else:
        if len(A)==0:
            flag = False
            break
        A.pop()
if not flag or len(A)>0:
    print("No")
else:
    A = []
    B = []
    for i in range(N):
        if S[i]=="(":
            if len(A)==0 or A[-1]=="(":
                A.append(S[i])
                B.append(S[i])
            else:
                A.append(S[i])
                B.append("+(")
        else:
            if A[-1]=="(":
                B.append("1+1)")
                A.pop()
                if len(A)==0 or A[-1]=="(":
                    A.append("1")
                elif A[-1]=="1":
                    A.pop()
                    A.append("2")
            elif A[-1]=="1":
                B.append("+1)")
                A.pop()
                A.pop()
                if len(A)==0 or A[-1]=="(":
                    A.append("1")
                elif A[-1]=="1":
                    A.pop()
                    A.append("2")
            else:
                B.append(")")
                A.pop()
                A.pop()
                if len(A)==0 or A[-1]=="(":
                    A.append("1")
                elif A[-1]=="1":
                    A.pop()
                    A.append("2")
    if A[0]=="1":
        B.append("+1")
    n = eval("".join(B))
    if K<n:
        print("No")
    else:
        B.append("+1"*(K-n))
        print("Yes")
        print("".join(B))
0