結果
問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
ユーザー |
|
提出日時 | 2025-07-02 11:00:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 92 ms / 2,000 ms |
コード長 | 1,568 bytes |
コンパイル時間 | 464 ms |
コンパイル使用メモリ | 82,464 KB |
実行使用メモリ | 85,064 KB |
最終ジャッジ日時 | 2025-07-02 11:00:46 |
合計ジャッジ時間 | 5,890 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
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") n += 1 if K<n: print("No") else: B.append("+1"*(K-n)) print("Yes") print("".join(B))