結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
ユーザー flippergo
提出日時 2025-07-02 10:46:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,561 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 167,252 KB
最終ジャッジ日時 2025-07-02 10:46:51
合計ジャッジ時間 10,329 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43 WA * 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")
    try:
        n = eval("".join(B))
    except:
        n = 0
    if K<n:
        print("No")
    else:
        B.append("+1"*(K-n))
        print("Yes")
        print("".join(B))
0