結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
コンテスト
ユーザー 👑 SPD_9X2
提出日時 2025-05-16 22:11:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 944 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 82,312 KB
実行使用メモリ 90,912 KB
最終ジャッジ日時 2025-05-17 00:29:10
合計ジャッジ時間 5,682 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #


import sys

N,K = map(int,input().split())

S = input()

ans = "Yes"

h = 0
for c in S:
    if c == "(":
        h += 1
    else:
        h -= 1

    if h < 0:
        ans = "No"

if h != 0:
    ans = "No"

if ans == "No":
    print ("No")
    sys.exit()



stk = []

ok = set()

for i in range(len(S)):

    if S[i] == "(":
        stk.append( i )

    elif S[i] == ")":
        stk.pop()
        if len(stk) > 0 and S[i+1] == "(":
            ok.add(stk[-1])

ans = []
num = 0

for i in range(len(S)):

    ans.append(S[i])
    if i == len(S)-1:
        continue

    if S[i] == "(" and S[i+1] == ")":
        ans.append("1+1")
        num += 2
    elif S[i] == "(" and S[i+1] == "(" and (i not in ok):
        ans.append("1+")
        num += 1
    elif S[i] == ")" and S[i+1] == "(":
        ans.append("+")


while num < K:
    ans.append("+1")
    num += 1

if num > K:
    print ("No")

else:
    print ("Yes")
    print ("".join(ans))
0