QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#37415#1194. Parehtneses EditorclaesWA 413ms6492kbC++1.3kb2022-07-01 13:23:302022-07-01 13:23:32

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 13:23:32]
  • 评测
  • 测评结果:WA
  • 用时:413ms
  • 内存:6492kb
  • [2022-07-01 13:23:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std ;
int st[200010] , top = 0 ;
int pp[200010] ;
char s[200010] ;
char ss[200010] ;
int pr[200010] ;
int ans[200010] ;
int main ()
{
	memset( pp , -1 , sizeof(pp) ) ;
	scanf("%s",s);
	if(s[0]=='(')
	{
		st[top] = 0 ;
		top ++ ;
	}
	ss[0] = '(' ;
	pr[0] = 0 ;
	puts("0");
	int wz = 1 ;
	for( int i = 1 ; i < strlen( s ) ; i ++ )
	{
//		cout<< s[i] << " T " << top << ' ' << ss[wz - 1] << endl ;
		if( s[i] == '(' )
		{
			ss[wz] = s[i] ;
			pr[wz] = 0 ;
			st[top] = wz ;
			top ++ ;
			ans[wz] = ans[wz - 1] ;
			printf( "%d\n" , ans[wz] ) ;
			wz ++ ;
		}
		else if( s[i] == ')' )
		{
			ss[wz] = s[i] ;
			ans[wz] = ans[wz - 1] ;
			if( top != 0 )
			{
//				cout<< "T" << ' ' << st[top - 1] << endl ;
				pp[wz] = st[top - 1] ;
				top -- ;
				ans[wz] ++ ;
				pr[wz] = pr[pp[wz] - 1] + 1 ;
				ans[wz] += pr[pp[wz] - 1] ;
			}
			else
			{
				pp[wz] = -1 ;
				pr[wz] = 0 ;
			}
			printf( "%d\n" , ans[wz] ) ;
			wz ++ ;
		}
		else
		{
			if( ss[wz - 1] == '(' )
			{
				top -- ;
			}
			else
			{
				if( pp[wz - 1] != -1 )
				{
					st[top] = pp[wz - 1] ;
					top ++ ;
				}
			}
			wz -- ;
			printf( "%d\n" , ans[wz - 1] ) ;
		}
//		cout<< pr[wz - 1] << ' ' << pp[wz - 1] << endl ;
	}
	return 0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6348kb

input:

(()())---)

output:

0
0
1
1
3
4
3
1
1
2

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 2ms
memory: 5792kb

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: 0
Accepted
time: 0ms
memory: 5832kb

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:

ok 20000 numbers

Test #4:

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

input:

(()())---)

output:

0
0
1
1
3
4
3
1
1
2

result:

ok 10 numbers

Test #5:

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

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 #6:

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

input:

(

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: 0
Accepted
time: 2ms
memory: 6260kb

input:

)

output:

0

result:

ok 1 number(s): "0"

Test #8:

score: 0
Accepted
time: 1ms
memory: 5868kb

input:

((

output:

0
0

result:

ok 2 number(s): "0 0"

Test #9:

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

input:

()

output:

0
1

result:

ok 2 number(s): "0 1"

Test #10:

score: 0
Accepted
time: 2ms
memory: 5808kb

input:

(-

output:

0
0

result:

ok 2 number(s): "0 0"

Test #11:

score: 0
Accepted
time: 2ms
memory: 4484kb

input:

)(

output:

0
0

result:

ok 2 number(s): "0 0"

Test #12:

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

input:

))

output:

0
0

result:

ok 2 number(s): "0 0"

Test #13:

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

input:

)-

output:

0
0

result:

ok 2 number(s): "0 0"

Test #14:

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

input:

(((((()((())()((()))

output:

0
0
0
0
0
0
1
1
1
1
2
3
3
5
5
5
5
6
7
10

result:

ok 20 numbers

Test #15:

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

input:

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

output:

0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1

result:

ok 20 numbers

Test #16:

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

input:

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

output:

0
0
0
0
0
1
1
1
1
1
1
1
2
2
2
3
3
3
3
3

result:

ok 20 numbers

Test #17:

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

input:

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

output:

0
0
0
0
0
0
0
1
0
1
1
1
1
1
1
2
2
2
2
3

result:

ok 20 numbers

Test #18:

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

input:

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

output:

0
0
0
0
1
2
2
2
2
2
2
3
3
3
3
3
3
3
3
3

result:

ok 20 numbers

Test #19:

score: 0
Accepted
time: 409ms
memory: 6400kb

input:

()))(((()))(()()))))(()))(()(()((())((())))(())()(()()((()())())))()(()()(()())())()())()()))()()()()))()))(())()()))()(()))(()((()())))()((()(((()(()))))))))()(((()(())(()))())()((((((((()))(())((()())()((()(()())))()))())))(()(()()((())()))()()()))))(((((()()(()())())(())())))())))()))(()()(()())(...

output:

0
1
1
1
1
1
1
1
2
3
4
4
4
5
5
7
9
10
10
10
10
10
11
12
12
12
12
13
13
13
14
14
14
14
15
16
16
16
16
17
18
20
22
22
22
23
26
26
30
30
30
31
31
33
33
33
33
34
34
36
37
37
39
42
47
49
49
52
52
52
53
53
55
55
55
56
56
58
61
61
65
69
69
74
74
80
81
81
83
83
86
86
86
86
87
87
89
89
92
92
96
96
96
96
97
97...

result:

ok 200000 numbers

Test #20:

score: -100
Wrong Answer
time: 413ms
memory: 6492kb

input:

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

output:

0
0
0
0
1
2
1
0
1
1
1
1
1
1
1
1
3
1
3
4
3
3
3
3
3
3
3
3
3
3
3
4
5
6
7
8
7
6
6
6
6
6
7
7
7
7
7
8
8
8
8
8
8
8
9
8
8
8
8
8
9
8
8
8
8
9
9
9
8
8
8
8
8
8
9
9
11
9
11
11
14
11
11
11
12
12
12
13
12
12
12
12
12
12
12
13
14
15
15
15
15
16
15
15
15
16
15
16
16
18
16
18
19
18
19
19
19
19
19
19
20
21
21
23
24
23...

result:

wrong answer 5th numbers differ - expected: '0', found: '1'