結果
問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
ユーザー |
|
提出日時 | 2025-07-02 10:58:03 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,553 bytes |
コンパイル時間 | 575 ms |
コンパイル使用メモリ | 82,252 KB |
実行使用メモリ | 84,916 KB |
最終ジャッジ日時 | 2025-07-02 10:58:11 |
合計ジャッジ時間 | 6,977 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 WA * 6 |
ソースコード
N,K = map(int,input().split()) S = input().strip() A = [] flag = True for i in range(N): if S[i]=="(": A.append(S[i]) else: if len(A)==0: flag = False break A.pop() if not flag or len(A)>0: print("No") else: A = [] B = [] n = 0 for i in range(N): if S[i]=="(": if len(A)==0 or A[-1]=="(": A.append(S[i]) B.append(S[i]) else: A.append(S[i]) B.append("+(") else: if A[-1]=="(": B.append("1+1)") n += 2 A.pop() if len(A)==0 or A[-1]=="(": A.append("1") elif A[-1]=="1": A.pop() A.append("2") elif A[-1]=="1": B.append("+1)") n += 1 A.pop() A.pop() if len(A)==0 or A[-1]=="(": A.append("1") elif A[-1]=="1": A.pop() A.append("2") else: B.append(")") A.pop() A.pop() if len(A)==0 or A[-1]=="(": A.append("1") elif A[-1]=="1": A.pop() A.append("2") if A[0]=="1": B.append("+1") if K<n: print("No") else: B.append("+1"*(K-n)) print("Yes") print("".join(B))