A. Treasure
time limit per test 2 seconds
memory limit per test 256 megabytes
input standard input
output standard output

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.

Input

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.

Output

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.

Sample test(s)
input
(((#)((#)
output
1
2
input
()((#((#(#()
output
2
2
1
input
#
output
-1
input
(#)
output
-1
Note

|s| denotes the length of the string s.

题意是要把#替换成1个以上的")",使得"("和“)”的个数相等,且对于s的任意一个前缀,“)“的个数不大于”)“的个数。

因为个数相等,所以分配给#的”)“的个数之和是确定的。

然后很显然的贪心是前k-1个#都只分配一个")",最后一个#多分配一点")"使”(“和”)"的个数相等就好了

于是变成模拟题了

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline void write(LL a)
{
if (a<0){printf("-");a=-a;}
if (a>=10)write(a/10);
putchar(a%10+'0');
}
char ch[100010];
int a[100010];
int s[100010];
int len,x,y,z,lst;
int main()
{
scanf("%s",ch);
for (int i=1;ch[i-1];i++)
{
if (ch[i-1]=='(')a[i]=1,x++;
if (ch[i-1]==')')a[i]=-1,y++;
if (ch[i-1]=='#')a[i]=0,z++,lst=i;
len=i;
}
if (x-y<z)
{
printf("-1");
return 0;
}
for (int i=1;i<=len;i++)
{
s[i]=s[i-1];
if (a[i]!=0)s[i]+=a[i];
else if (i==lst)s[i]-=x-(y+z-1);
else s[i]--;
if (s[i]<0)
{
printf("-1");
return 0;
}
}
for (int i=1;i<z;i++)
printf("1\n");
printf("%d\n",x-y-(z-1));
}

cf494A Treasure的更多相关文章

  1. Windows Phone 8.1低功耗蓝牙开发-Nokia Treasure Tag

    1. 引言 上一篇文章<Windows 8.1 低功耗蓝牙开发>讲述了如何在Windows 8.1平台上创建低功耗蓝牙应用,并且以TI的Sensor Tag为例,给出了代码步骤和演示.其实 ...

  2. ZOJ 3209 Treasure Map (Dancing Links)

    Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 KB Your boss once had got many copies of ...

  3. poj 2594 Treasure Exploration (二分匹配)

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 6558   Accepted: 2 ...

  4. hdu 5446 Unknown Treasure Lucas定理+中国剩余定理

    Unknown Treasure Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  5. POJ 1473 There's Treasure Everywhere!

    题目链接 小小的模拟一下. #include <cstdio> #include <cstring> #include <string> #include < ...

  6. hdu 5446 Unknown Treasure 卢卡斯+中国剩余定理

    Unknown Treasure Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  7. POJ2594 Treasure Exploration

    Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8193   Accepted: 3358 Description Have ...

  8. zoj Treasure Hunt IV

    Treasure Hunt IV Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is exploring the wonderland ...

  9. HDU 5446 Unknown Treasure Lucas+中国剩余定理

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5446 Unknown Treasure 问题描述 On the way to the next se ...

随机推荐

  1. 使用MapReduce将HDFS数据导入到HBase(二)

    package com.bank.service; import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.conf. ...

  2. Linux下基于源代码方式安装MySQL 5.6

    MySQL为开源数据库,因此能够基于源代码实现安装.基于源代码安装有很多其它的灵活性. 也就是说我们能够针对自己的硬件平台选用合适的编译器来优化编译后的二进制代码.依据不同的软件平台环境调整相关的编译 ...

  3. Java基础知识强化58:经典排序之二叉树排序(BinaryTreeSort)

    1. 二叉树排序 二叉树排序的描述也是一个递归的描述, 所以二叉树排序的构造自然也用递归的: 二叉排序树或者是一棵空树,或者是具有下列性质的二叉树: (1)若左子树不空,则左子树上所有结点的值均小于它 ...

  4. cordova热更新

    cordova 热更新: 一.添加插件 1.新建Cordova项目 cordova create CordovaHotCode com.ezample.hotcode 2.添加Android平台 在新 ...

  5. Cretiria查询应用(二)

    1.条件查询,动态查询 public void conditionQuery(){ Session session=null; try { session=HibernateUtil.currentS ...

  6. IPointCollection,ISegmentCollection和IGeometryCollection

    Engine 提供了三个主要的几何图形集合接口用于对几何对象的操作,分别是 IPointCollection,ISegmentCollection 和 IGeometryCollection,这些接口 ...

  7. OC随笔一:类

    总结:        在oc中,我们要整出一个类来,首先需要一个.h头文件和一个.m实现文件.一般我们创建的类都继承了根类,因为根类帮我们实现了很多实用的方法,而类里面会有变量(属性) .函数(方法) ...

  8. C#多线程实践——创建和开始使用

    线程用Thread类来创建, 通过ThreadStart委托来指明方法从哪里开始运行.ThreadStart的声明如下: public delegate void ThreadStart(); 调用S ...

  9. C#double保留两位小数

    public static void Main(string[] args) { double db = Math.PI; db = Math.Round(db,); Console.WriteLin ...

  10. 随笔: WC2016感想

    在某些时刻,我可以体会到非常复杂的情感,这种情感神秘的来源不能被描述.它非常的复杂.你无法分清,这种情感是来源于一个个神经元控制的情感系统的一时冲动,亦或是你如实地反馈了你所正在感知的外界. 但我曾在 ...