結果
| 問題 | No.3143 Colorless Green Parentheses Sleep Furiously |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-05-16 22:19:01 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,137 bytes |
| 記録 | |
| コンパイル時間 | 226 ms |
| コンパイル使用メモリ | 95,600 KB |
| 実行使用メモリ | 97,408 KB |
| 最終ジャッジ日時 | 2026-07-10 19:15:19 |
| 合計ジャッジ時間 | 6,999 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| 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 len(st) == 0:
return False
elif 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:
print('Yes')
print(t + ('+1' * (K - cnt)))
else:
print('No')
solve(K, S)
norioc