CF494A.Treasure

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string s written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful.

Below there was also written that a string is called beautiful if for each i (1 ≤ i ≤ |s|) there are no more ')' characters than '(' characters among the first i characters of s and also the total number of '(' characters is equal to the total number of ')' characters.

Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with.

马莱克最近发现了一张藏宝图。当他寻找宝藏时,他发现了一扇上锁的门。门上写着一个由字符 '('、')' 和 '#' 组成的字符串 $ s $。门下还附有一份操作手册,说明如何打开这扇门。经过长时间的研究,马莱克成功破译了手册,得知目标是将每个 '#' 替换为一个或多个 ')' 字符,使得最终得到的字符串是“优美的”。

手册中还指出:一个字符串被称为优美的,当且仅当对每个 $ i (( 1 \leq i \leq |s| $),在 $ s $ 的前 $ i $ 个字符中,')' 的数量不超过 '(' 的数量,并且整个字符串中 '(' 的总数等于 ')' 的总数。

请帮助马莱克打开这扇门,告诉他每个 '#' 字符应被替换为多少个 ')' 字符。

输入格式

The first line of the input contains a string s (1 ≤ |s| ≤ 105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that s contains at least one '#' character.

输入的第一行包含一个字符串 ss(1 ≤ ∣s∣ ≤ 1051 \leq |s| \leq 10^5)。该字符串的每个字符均为 '('、')' 或 '#' 中的一个。保证 ss 中至少包含一个 '#' 字符。

输出格式

If there is no way of replacing '#' characters which leads to a beautiful string print  - 1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with.

If there are several possible answers, you may output any of them.

如果不存在将 # 字符替换为某些字符从而得到优美字符串的方法,则输出 -1。否则,对每个字符 #,单独输出一行,该行包含一个正整数,表示该 # 字符必须被替换为的 ) 字符的个数。

如果存在多个可能的答案,你可以输出其中任意一个。

输入输出样例

  • 输入#1

    (((#)((#)

    输出#1

    1
    2
  • 输入#2

    ()((#((#(#()

    输出#2

    2
    2
    1
  • 输入#3

    #

    输出#3

    -1
  • 输入#4

    (#)

    输出#4

    -1

说明/提示

|s| denotes the length of the string s.

∣s∣|s| 表示字符串 ss 的长度。

输入解题思路,AI测评打分。不知道怎么写?

首页