結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
ユーザー hato336
提出日時 2025-05-16 22:26:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,083 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 82,316 KB
実行使用メモリ 131,280 KB
最終ジャッジ日時 2025-05-17 00:31:54
合計ジャッジ時間 6,873 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = map(int,input().split())
s = list(input().rstrip())
x = 0
for i in s:
    x += 1 if i == '(' else -1
    if x < 0:
        print('No')
        exit()
if x != 0:
    exit(print('No'))
st = []
ans = 0
a = [[] for i in range(n)]
t = set()
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(")")
        t.add((j,i))
        st.pop()
    else:
        st.append((x,i))
for j,i in t:
    if (j+1,i-1) in t:
        if a[i] == list(")"):
            a[i] = list("+1)")
            ans += 1
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