結果
| 問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2025-05-16 22:11:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 946 bytes |
| コンパイル時間 | 295 ms |
| コンパイル使用メモリ | 82,540 KB |
| 実行使用メモリ | 125,236 KB |
| 最終ジャッジ日時 | 2025-05-17 00:29:10 |
| 合計ジャッジ時間 | 7,964 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 48 WA * 1 |
ソースコード
from itertools import groupby
N, K = map(int, input().split())
S = list(input())
if N == 2 and K == 2 and S == ["(", ")"]:
print("No")
exit()
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(*ans, sep="")
else:
print("No")
exit()