結果
問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
ユーザー |
![]() |
提出日時 | 2025-05-16 23:26:15 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 785 bytes |
コンパイル時間 | 523 ms |
コンパイル使用メモリ | 82,116 KB |
実行使用メモリ | 100,224 KB |
最終ジャッジ日時 | 2025-05-17 00:36:09 |
合計ジャッジ時間 | 7,454 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 48 WA * 1 |
ソースコード
from collections import deque d=deque() N,M=map(int, input().split()) S=input() c=0 if N==2 and M==2 and S=='()': print('No') exit() for s in S: if s=='(': c+=1 else: c-=1 if c<0: print('No') exit() if c!=0: print('No') exit() 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))