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. Css定位-定位

    在CSS中一共有N种定位方式,其中,static ,relative,absolute三种方式是最基本最常用的三种定位方式.他们的基 本介绍如下. static默认定位方式 relative相对定位, ...

  2. MyEclipse中用Maven创建Web项目(亲测有效)

    new --> other   1.Wizards: mvaen 2.Maven Project 3.Next   Use Default Workspace Location   1.weba ...

  3. eclipse format的时候如何让@param后不换行

  4. Android Paint之 setXfermode PorterDuffXfermode 讲解

    setXfermodePorterDuffXfermode图层混合模式android图像混合模式AvoidXfermode 尊重原创,欢迎转载,转载请注明: FROM  GA_studio   htt ...

  5. Java 泛型数组

    Java 不支持泛型数组.也就是说, List<String>[] ls = new ArrayList<String>[10]; 是不支持的,而 List<String ...

  6. Matlab生成二类线性可分数据

    %% 生成二类线性可分数据 function [feature, category]=generate_sample(step,error) aa=3; %斜率 bb=3; %截距 b1=1; rr ...

  7. getChars的使用方法

    <%@ page contentType="text/html; charset=gb2312" %> <%@ page import="java.ut ...

  8. 为什么HikariCP被号称为性能最好的Java数据库连接池,怎样配置使用

    HiKariCP是数据库连接池的一个后起之秀.号称性能最好.能够完美地PK掉其它连接池. 原文地址:http://blog.csdn.net/clementad/article/details/469 ...

  9. NSRunLoop个人理解

    作者: xwang 出处: http://www.cnblogs.com/xwang/  本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保 ...

  10. oracle 按某个字段查询重复数据

    /* 手机号为重复的会员,获取其最大会员id,对应的会员信息 */ SELECT * FROM MEMBER a WHERE a.member_id IN ( SELECT MAX(member_id ...