結果
| 問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2025-05-16 22:07:46 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 876 bytes |
| コンパイル時間 | 496 ms |
| コンパイル使用メモリ | 82,112 KB |
| 実行使用メモリ | 111,312 KB |
| 最終ジャッジ日時 | 2025-05-17 00:28:39 |
| 合計ジャッジ時間 | 6,929 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 WA * 2 |
ソースコード
from itertools import groupby
N, K = map(int, input().split())
S = list(input())
def is_valid(S):
stack = []
for s in S:
stack.append(s)
if len(stack) >= 2 and stack[-2:] == ["(", ")"]:
stack.pop()
stack.pop()
return len(stack) == 0
if not is_valid(S):
print("No")
exit()
rle = [(k, len(list(v))) for k, v in groupby(S)]
ans = []
for k, v in rle:
if k == "(":
for i in range(v):
ans.append("(")
ans.append("1")
ans.append("+")
else:
ans.append("1")
for i in range(v):
ans.append(")")
ans.append("+")
ans.pop()
if ans.count("1") <= K:
cnt = ans.count("1")
for i in range(K - cnt):
ans.append("+")
ans.append("1")
print("Yes")
print("".join(ans))
else:
print("No")
exit()