結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
ユーザー tkykwtnb
提出日時 2025-05-16 22:10:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 817 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 82,636 KB
実行使用メモリ 95,360 KB
最終ジャッジ日時 2025-05-17 00:29:03
合計ジャッジ時間 6,716 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39 WA * 4 RE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int,input().split())
S=list(input())
stack=[]
mn=0
for s in S:
    if s=="(":stack.append(s)
    else:
        stack.pop()
        mn+=2
        if len(stack)>0:mn-=1
if len(stack)>0 or mn>K:exit(print("No"))
ans=[]
sm=0
depth=0
for s in S:
    if s=="(":
        if len(ans)>0 and ans[-1]==")":
            ans.append("+")
        ans.append(s)
        ans.append("1+")
        sm+=1
        stack.append(s)
        depth+=1
    else:
        if depth==1:
            ans.append("1")
            ans.append(s)
            sm+=1
            stack.pop()
        else:
            if ans[-1]=="1+":
                ans.append("1")
                sm+=1
            ans.append(s)
            stack.pop()
        if len(stack)==0:depth=0
while sm<K:
    ans.append("+1")
    sm+=1
print("Yes")
print("".join(ans))
0