結果
問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
ユーザー |
|
提出日時 | 2025-05-16 22:22:41 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 723 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 82,900 KB |
実行使用メモリ | 94,976 KB |
最終ジャッジ日時 | 2025-05-17 00:30:54 |
合計ジャッジ時間 | 5,739 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 WA * 4 |
ソースコード
N,K=map(int,input().split()) S=list(input()) stack=[] mn=0 for s in S: if s=="(":stack.append(s) else: if len(stack)==0:exit(print("No")) stack.pop() mn+=2 if len(stack)>0:mn-=1 if len(stack)>0 or mn>K:exit(print("No")) ans=[] sm=0 for s in S: if s=="(": if len(ans)>0 and ans[-1]==")": ans.append("+") ans.append(s) ans.append("1+") sm+=1 stack.append(s) else: if ans[-1]=="1+": ans.append("1") sm+=1 ans.append(s) stack.pop() else: ans.append(s) stack.pop() while sm<K: ans.append("+1") sm+=1 print("Yes") print("".join(ans))