結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
ユーザー tassei903
提出日時 2025-05-16 21:42:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 873 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 82,520 KB
実行使用メモリ 75,960 KB
最終ジャッジ日時 2025-05-17 00:23:39
合計ジャッジ時間 5,523 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().strip()
ni = lambda : int(input())
na = lambda : list(map(int, input().split()))
yes = lambda : print("yes"); Yes = lambda : print("Yes"); YES = lambda : print("YES")
no = lambda : print("no"); No = lambda : print("No"); NO = lambda : print("NO")

n, k = na()
S = input()
n = len(S)

res = []
a = [0] * n
s = 0

for i in range(n):
    if S[i] == "(":
        if a[s]:
            res.append("+")
        a[s] += 1
        s += 1
        res.append("(")
    else:
        if a[s] == 0:
            res.append("1+1)")
            k -= 2
        elif a[s] == 1:
            res.append("+1)")
            k -= 1
        else:
            res.append(")")
        a[s] = 0
        s -= 1
if a[0] == 1:
    res.append("+1")
    k -= 1

# print("".join(res))
if k >= 0:
    Yes()
    print("".join(res + ["+1"] * k))
else:
    No()
0