結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
ユーザー hato336
提出日時 2025-05-16 22:14:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 802 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 115,708 KB
最終ジャッジ日時 2025-05-17 00:29:54
合計ジャッジ時間 10,574 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = map(int,input().split())
s = list(input().rstrip())
st = []
ans = 0
a = [[] for i in range(n)]
for i in range(n):
    x = s[i]
    if st and st[-1][0] == '(' and x == ')':
        j = st[-1][1]
        if j + 1 == i:
            ans += 2
            a[j] = list("(1+1)")
        elif j + 3 == i:
            ans += 1
            a[j] = list("(")
            a[i] = list("+1)")
        else:
            ans += 0
            a[j] = list("(")
            a[i] = list(")")
        st.pop()
    else:
        st.append((x,i))
if ans <= k:
    print('Yes')
    b = []
    for i in a:
        if i and i[0] == '(' and len(b) > 0 and b[-1] == ')':
            b.append('+')
        b.extend(i)
    while ans < k:
        ans += 1
        b.extend(list("+1"))
    print(''.join(b))
else:
    print('No')
0