結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
ユーザー SPD_9X2
提出日時 2025-05-16 22:13:34
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,005 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 90,964 KB
最終ジャッジ日時 2025-05-17 00:29:34
合計ジャッジ時間 6,042 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 48 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #


import sys

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

if N == K == 2 and S == "()":
    print ("No")
    sys.exit()

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