結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
ユーザー pitP
提出日時 2025-05-16 22:10:33
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 939 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 14,080 KB
最終ジャッジ日時 2025-05-17 00:29:00
合計ジャッジ時間 5,427 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 48 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
L = K
S = list(input())
A = [1 if S[i] == '(' else -1 for i in range(N)]

def c_problem():
    wa = 0
    for i in range(N):
        wa += A[i]
        if wa < 0:
            return False

    return wa == 0

if not c_problem():
    exit(print("No"))

ans = []
for i in range(N):
    if len(ans) > 0:
        if ans[-1] == '(' and S[i] == ')':
            K -= 2
            ans.append('1+1')
        elif ans[-1] == ')' and S[i] == '(':
            ans.append('+')
        elif ans[-1] == ')' and S[i] == ')':
            K -= 1
            ans.append('+1')
    
    ans.append(S[i])

if K < 0:
    print("No")
else:
    for _ in range(K):
        ans.append('+1')
    
    wa = 0
    c = 0
    for i in range(N):
        wa += A[i]
        if wa == 0:
            c += 1

    if c == 1 and (ans[0] == '(' and ans[-1] == ')'):
        print("No")
    else:
        print("Yes")
        print("".join(ans))
0