結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
ユーザー 👑 p-adic
提出日時 2025-05-17 01:03:47
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 338 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 12,288 KB
実行使用メモリ 12,356 KB
最終ジャッジ日時 2025-05-17 01:03:54
合計ジャッジ時間 5,829 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

I=input
N,K=map(int,I().split())
S=I()
s=[]
E=[]
for i in range(N):
	if S[i]<')':
		if E and E[-1][-1]==')':E+=["+("];s+=[0]
		else:E+=["("];s+=[1]
	else:
		if not s:K=-1;break
		if E and E[-1][-1]<')':E+=["1+1)"];K-=2
		else:E+=[")"]
		if s.pop()*(i==N-1 or S[i+1]>'('):E+=["+1"];K-=1
print("No"if K<0 or s else"Yes\n"+''.join(E)+"+1"*K)
0