結果

問題 No.3143 Colorless Green Parentheses Sleep Furiously
ユーザー timi
提出日時 2025-05-17 12:40:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 963 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 82,024 KB
実行使用メモリ 107,528 KB
最終ジャッジ日時 2025-05-17 12:41:10
合計ジャッジ時間 9,385 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
d=deque()
N,M=map(int, input().split())
S=input()
A=[0]
for s in S:
  if s=='(':
    A.append(A[-1]+1)
  else:
    A.append(A[-1]-1)
    
if min(A)<0 or A[-1]!=0:
  print('No')
  exit()
  
A=A[1:-1]
f=0
if min(A)==1:
  f=1
  
D={}
for i in range(N-1):
  if S[i]=='('and S[i+1]==')':
    if i not in D:
      D[i]=[]
    D[i].append('1+1')
    l,r=i,i+1
    while True:
      l-=1;r+=1 
      if l<0 or N<=r:
        break 
      if S[l]=='('and S[r]==')':
        if r-1 not in D:
          D[r-1]=[]
        D[r-1].append('+1')
      else:
        break
  if S[i]==')'and S[i+1]=='(':
    if i not in D:
      D[i]=[]
    D[i].append('+')
    
ans=[]
for i in range(N):
  ans.append(S[i])
  if i in D:
    ans.append(D[i][0])

ans=''.join(ans)
if f==1:
  ans=ans+'+1'
  ans=''.join(ans)

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