結果
| 問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-16 22:32:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,139 bytes |
| コンパイル時間 | 177 ms |
| コンパイル使用メモリ | 82,216 KB |
| 実行使用メモリ | 131,408 KB |
| 最終ジャッジ日時 | 2025-05-17 00:33:02 |
| 合計ジャッジ時間 | 6,730 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 WA * 2 |
ソースコード
n,k = map(int,input().split())
s = list(input().rstrip())
x = 0
for i in s:
x += 1 if i == '(' else -1
if x < 0:
print('No')
exit()
if x != 0 or n == 2:
exit(print('No'))
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:
if a[i] == list(")"):
a[i] = list("+1)")
ans += 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)
#b.extend(list("+1"))
#ans+=1
while ans < k:
ans += 1
b.extend(list("+1"))
print(''.join(b))
else:
print('No')