結果
問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
ユーザー |
|
提出日時 | 2025-05-16 22:17:05 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 897 bytes |
コンパイル時間 | 309 ms |
コンパイル使用メモリ | 82,584 KB |
実行使用メモリ | 139,168 KB |
最終ジャッジ日時 | 2025-05-17 00:30:26 |
合計ジャッジ時間 | 10,452 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 WA * 36 |
ソースコード
n,k = map(int,input().split()) s = list(input().rstrip()) st = [] ans = 0 a = [[] for i in range(n)] t = set() for i in range(n): x = s[i] if st and st[-1][0] == '(' and x == ')': j = st[-1][1] if j + 1 == i: ans += 2 a[j] = list("(1+1)") elif j + 3 == i: ans += 1 a[j] = list("(") a[i] = list("+1)") else: ans += 0 a[j] = list("(") a[i] = list(")") t.add((j,i)) st.pop() else: st.append((x,i)) for j,i in t: if (j+1,i-1) in t: a[i] = list("+1)") if ans <= k: print('Yes') b = [] for i in a: if i and i[0] == '(' and len(b) > 0 and b[-1] == ')': b.append('+') b.extend(i) while ans < k: ans += 1 b.extend(list("+1")) print(''.join(b)) else: print('No')