QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#37401#1194. Parehtneses EditorclaesWA 4ms7768kbC++1.2kb2022-07-01 12:53:082022-07-01 12:53:10

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-01 12:53:10]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:7768kb
  • [2022-07-01 12:53:08]
  • 提交

answer

//Leo
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define N 200200
using namespace std;
int cnt,len,q[N],Q[N],op[N];
int ans[N],suma[N],sumb[N],pre[N];
char st[N];

void solve(int i,int p)
{
	int r=q[cnt--];
//	printf("%d ",r);
	op[i]=r;
//	if(suma[p-1]-suma[r] == sumb[p-1]-sumb[r])
//		if(suma[p-1]-suma[r] == pre[p-1]) flag=true;
//	printf("KKK %d %d %d\n",suma[p-1]-suma[r],sumb[p-1]-sumb[r],pre[p-1]);
//	printf("%d\n",flag);
	pre[p]=pre[r-1]+1;ans[p]+=pre[p];
}

int main()
{
	scanf("%s",st);
	Q[0]=0;
	if(st[0]=='(') q[++cnt]=0;
	ans[0]=0;
	puts("0");
	
	for(int i=1,j=1;i<strlen(st);i++,j++){
		ans[j]=ans[j-1];
		if(i==1213) putchar(st[i]);
		if(st[i]=='('){
			q[++cnt]=j;
			pre[j]=0;
			Q[++len]=i;
			printf("%d\n",ans[j]);
		}
		else if(st[i]==')'){
			if(cnt) solve(i,j);
			else pre[j]=0;
			Q[++len]=i;
			printf("%d\n",ans[j]);
		}
		else{
			j--;
			if(st[Q[len]]==')') q[++cnt]=op[Q[len]];
			else cnt--;
			len--;
			printf("%d\n",ans[--j]);
		}
//		printf("len=%d %d\n",len,Q[len]);
//		putchar('q');
//		for(int k=1;k<=cnt;k++) printf(" %d",q[k]);
//		puts("");
	}
	return 0;
}

/*
))(((-)(()((---(-)(-())-(()()(-)--(()))
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7768kb

input:

(()())---)

output:

0
0
1
1
3
4
3
1
1
2

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 5832kb

input:

()--()()----)(()()))

output:

0
1
0
0
0
1
1
3
1
1
0
0
0
0
0
1
1
3
4
4

result:

ok 20 numbers

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 5860kb

input:

))(((-)(()((---(-)(-())-(()()(-)--(())))--()((())-)(()(())((-))))(-(((()((()()()()))-(())((((--))-())-)(-(--))))((((-)(-(-)((((()--(---)(-))()(-)(()()-(())()(()()((()()))))(()(()(-(--)-()((()(((()-))-)(()-()()-(-((-)(-)(((()-)))))-())()-(()((()(-)()))((-))())))()()()(-(-(())-()(()-)-))((()))((--(-()...

output:

0
0
0
0
0
0
1
1
1
2
2
2
2
2
1
1
1
2
2
2
2
4
6
4
4
4
5
5
7
7
7
10
7
5
5
5
6
7
9
12
9
7
7
9
9
9
9
10
11
10
11
11
11
12
12
12
13
15
15
15
15
18
20
23
25
25
25
25
25
25
25
26
26
26
26
27
27
29
29
32
32
36
37
39
37
37
37
38
40
40
40
40
40
40
40
41
44
41
41
43
46
43
46
46
46
46
46
43
46
48
49
50
50
50
50
...

result:

wrong output format Expected integer, but ")774" found