結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
コンテスト
ユーザー 👑 p-adic
提出日時 2025-05-17 01:03:47
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 338 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 809 ms
コンパイル使用メモリ 21,540 KB
実行使用メモリ 17,020 KB
最終ジャッジ日時 2026-07-10 19:41:17
合計ジャッジ時間 9,187 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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