QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#37359#1194. Parehtneses EditorclaesWA 8ms7836kbC++1.0kb2022-07-01 11:12:492022-07-01 11:12:49

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 11:12:49]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:7836kb
  • [2022-07-01 11:12:49]
  • 提交

answer

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

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

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

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 5804kb

input:

(()())---)

output:

0
0
1
1
3
4
3
1
1
2

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 3ms
memory: 7832kb

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: 8ms
memory: 7836kb

input:

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

output:

0
0
0
0
0
0
1
1
1
2
2
2
2
2
1
1
1
1
1
1
1
2
2
2
2
2
3
3
5
5
5
7
5
3
3
3
3
3
3
3
3
3
3
4
4
4
4
5
5
5
5
5
5
5
5
5
6
7
7
7
7
9
9
9
9
9
9
9
9
9
9
10
10
10
10
11
11
13
13
16
16
20
21
21
21
21
21
22
24
24
24
24
24
24
24
25
28
25
25
27
27
27
27
27
27
27
27
27
27
27
28
28
28
28
28
28
28
29
29
29
29
29
30
30...

result:

wrong answer 18th numbers differ - expected: '2', found: '1'