結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
ユーザー timi
提出日時 2025-05-16 22:23:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 606 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 102,012 KB
最終ジャッジ日時 2025-05-17 00:31:05
合計ジャッジ時間 7,421 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39 WA * 7 RE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
d=deque()
N,M=map(int, input().split())
S=input()
A=[]
cnt=0
for s in S:
  if s=='(':
    d.append('(')
  else:
    if d[-1]=='(':
      d.append('1')
      d.append('+')
      d.append('1')
      cnt+=2
    d.append(')')

ans=[]
while d:
  c=d.popleft()
  if len(ans)==0:
    ans.append(c) 
  else:
    if ans[-1]==')' and c=='(':
      ans.append('+')
    elif ans[-1]=='(' and c=='(':
      ans.append('1')
      ans.append('+')
      cnt+=1
    ans.append(c)

if cnt>M:
  print('No')
else:
  for i in range(M-cnt):
    ans.append('+1')
  print('Yes')
  print(''.join(ans))
0