結果
| 問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-05-17 02:04:04 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,171 bytes |
| コンパイル時間 | 447 ms |
| コンパイル使用メモリ | 82,688 KB |
| 実行使用メモリ | 82,304 KB |
| 最終ジャッジ日時 | 2025-05-17 02:04:11 |
| 合計ジャッジ時間 | 5,925 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 47 WA * 2 |
ソースコード
N, K = map(int, input().split())
S = input()
def is_balanced(s: str) -> bool:
d = 0
for c in S:
if c == '(':
d += 1
elif c == ')':
if d == 0:
return False
d -= 1
return d == 0
def solve(k: int, s: str):
if not is_balanced(s):
print('No')
return
st = []
for c in S:
if c == '(':
if len(st) == 0:
st.append(c)
elif st[-1] == ')':
st.append('+')
st.append(c)
elif st[-1] == '(':
st.append('1+')
st.append(c)
else:
assert False
elif c == ')':
if st[-1] == '(':
st.append('1+1')
st.append(c)
elif st[-1] == ')':
st.append(c)
else:
assert False
t = ''.join(st)
cnt = t.count('1')
if cnt <= K:
ans = t + ('+1' * (K - cnt))
if ans.endswith(')'):
print('No')
else:
print('Yes')
print(ans)
else:
print('No')
solve(K, S)
norioc