QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#490338#7683. Hard Brackets Problemucup-team3160#WA 24ms7712kbC++14551b2024-07-25 14:45:362024-07-25 14:45:36

Judging History

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

  • [2024-07-25 14:45:36]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:7712kb
  • [2024-07-25 14:45:36]
  • 提交

answer

# include <bits/stdc++.h>

using namespace std ;

int stk[1000005] , top ;
int n ;
char s[1000005] ;
int pre[100005] ;
void solve()
{
	scanf("%s" , s + 1) ;
	n = strlen( s + 1 ) ;
	top = 0 ;
	for ( int i = 1 ; i <= n ; i++ )
	{
		pre[i] = 0 ;
		if ( s[i] == '(' )
		{
			stk[++ top] = i ;
		}
		else
		{
			if ( top ) pre[i] = stk[top --] ; 
		}
	}
	if ( top ) 
	{
		puts("impossible") ;
		return ;
	}
	printf("%s\n" , s + 1) ;
}

int main()
{
	int t ;
	scanf("%d" , &t) ;
	while ( t -- ) solve() ;
	return 0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3728kb

input:

3
((()))
(
)))()

output:

((()))
impossible
)))()

result:

ok 3 cases (3 test cases)

Test #2:

score: 0
Accepted
time: 13ms
memory: 3892kb

input:

100000
())(()()()
()())()))
)()()()()
())()(())(
((())()))
)(())()))(
)()))())))
)))))(((()
()))((()((
()((()()))
(()())())
())(()))()
(())(())))
))))(()(()
()))(())((
()((())())
()))()))()
()((())())
()()))((()
()))(()))
(()(())))
())((()))
())()((())
(()(())))
()(((()())
))))())))(
((((()()()
(()(...

output:

impossible
()())()))
)()()()()
impossible
((())()))
impossible
)()))())))
impossible
impossible
()((()()))
(()())())
())(()))()
(())(())))
impossible
impossible
()((())())
()))()))()
()((())())
impossible
()))(()))
(()(())))
())((()))
impossible
(()(())))
impossible
impossible
impossible
impossible
...

result:

ok 100000 cases (100000 test cases)

Test #3:

score: 0
Accepted
time: 17ms
memory: 5796kb

input:

200000
(()))
()))(
)()))
(())
)((((
)(())
)(())
()))(
((()(
()(()
))())
)((((
()())
(())
()(()
(()()
)(())
()))
(()()
()())
(())
()()(
(()((
)())
(()()
(())
))(((
(())
())()
())()
(()))
(((((
)())
(()))
()(()
)()()
(()))
()())
(()))
)(())
(())(
))))(
())((
))(((
))))(
()()
()())
(())
(())
(())
)(())...

output:

(()))
impossible
)()))
(())
impossible
)(())
)(())
impossible
impossible
impossible
))())
impossible
()())
(())
impossible
impossible
)(())
()))
impossible
()())
(())
impossible
impossible
)())
impossible
(())
impossible
(())
())()
())()
(()))
impossible
)())
(()))
impossible
)()()
(()))
()())
(()))...

result:

ok 200000 cases (200000 test cases)

Test #4:

score: 0
Accepted
time: 24ms
memory: 5796kb

input:

250000
()()
(())
())
)(((
(()(
(())
)()
(())
(())
))()
)(()
)())
)())
(())
)())
()))
())
(()(
))))
()((
()()
)())
())
())
())
(())
))()
(())
(()(
)))(
()))
())
)))(
)(()
()))
()()
(())
((()
(())
))((
))((
(())
()))
(()(
(())
((()
)(()
(())
((((
())
))()
())
()()
)()(
)()
(())
))()
()))
())
)()
)())
...

output:

()()
(())
())
impossible
impossible
(())
)()
(())
(())
))()
impossible
)())
)())
(())
)())
()))
())
impossible
))))
impossible
()()
)())
())
())
())
(())
))()
(())
impossible
impossible
()))
())
impossible
impossible
()))
()()
(())
impossible
(())
impossible
impossible
(())
()))
impossible
(())
impo...

result:

ok 250000 cases (250000 test cases)

Test #5:

score: 0
Accepted
time: 7ms
memory: 3800kb

input:

50000
)))()((((()(((())(()
)(())()())((())))()(
(((((()))()(((()((()
)()(()())(()())(()()
()(())()()()((())))
)((())))((((())(((((
((())(()()))()(()())
()))())(()))(()())((
))(((())(())()))())
((((()())()))()(((((
((())()))))(((()))))
()()(())((()(()))))
()())())))()()(()))
()))(())()())()(())
()()(...

output:

impossible
impossible
impossible
impossible
()(())()()()((())))
impossible
((())(()()))()(()())
impossible
))(((())(())()))())
impossible
((())()))))(((()))))
()()(())((()(()))))
()())())))()()(()))
()))(())()())()(())
impossible
)))))(())()())((()))
impossible
)(((()())()(())()))
impossible
impossi...

result:

ok 50000 cases (50000 test cases)

Test #6:

score: 0
Accepted
time: 8ms
memory: 3792kb

input:

83333
((()((())(()
(())(()()))
()(()(())))
((((())))))
)())(((())))
()()())()())
()()((())))
(()(()(((())
()((()()()()
(()()()())))
(()()()(((()
)))))()()())
)((()()())))
))(((()))))
()())(()))()
)()))))()())
)(()((())))(
(()())(()))
())()((())))
(()()()(()))
)())()()(())
((())()))(()
(()(()(((())
)...

output:

impossible
(())(()()))
()(()(())))
((((())))))
)())(((())))
()()())()())
()()((())))
impossible
impossible
(()()()())))
impossible
)))))()()())
)((()()())))
))(((()))))
()())(()))()
)()))))()())
impossible
(()())(()))
())()((())))
(()()()(()))
)())()()(())
impossible
impossible
impossible
impossible...

result:

ok 83333 cases (83333 test cases)

Test #7:

score: 0
Accepted
time: 23ms
memory: 3792kb

input:

250000
)))
)(((
()()
((()
((()
())
())(
))((
)())
()()
()()
())
((()
())
()()
(())
(())
()()
()))
())
)())
()()
)()
())
)()(
(())
)()
)(((
))()
(())
)()
)())
)()
)()
))((
()()
(())
()((
))((
)(((
()))
)())
)())
)())
)())
)(((
())
)))
(())
(())
())(
())
(())
(())
()()
())(
()()
())
))()
(())
(())
)()...

output:

)))
impossible
()()
impossible
impossible
())
impossible
impossible
)())
()()
()()
())
impossible
())
()()
(())
(())
()()
()))
())
)())
()()
)()
())
impossible
(())
)()
impossible
))()
(())
)()
)())
)()
)()
impossible
()()
(())
impossible
impossible
impossible
()))
)())
)())
)())
)())
impossible
())...

result:

ok 250000 cases (250000 test cases)

Test #8:

score: 0
Accepted
time: 10ms
memory: 5800kb

input:

50000
(())((()()(())(((()(
()()()((((()())())))
(())(()()()((())))()
(())(()))(()(()()))
()((((()((())))))))
)))())))()()())()))(
()(()))(((())()(((((
()()())())(((()())))
(())(())))(()((())))
()(()(())()()()()(((
()()()((()(()()))))
)(())))()(())()())()
)((((((()())())((())
)()())(()((()(()))))
(()...

output:

impossible
()()()((((()())())))
(())(()()()((())))()
(())(()))(()(()()))
()((((()((())))))))
impossible
impossible
()()())())(((()())))
(())(())))(()((())))
impossible
()()()((()(()()))))
)(())))()(())()())()
impossible
)()())(()((()(()))))
(())(()()())()())())
)())()()()()((())())
(())()((())((()))...

result:

ok 50000 cases (50000 test cases)

Test #9:

score: 0
Accepted
time: 13ms
memory: 3804kb

input:

83333
((()(())))()
()))()()))()
()))()))())(
())(())))())
)()))))(((((
)(()(()())((
(()))(())())
)()()()(()()
((()())((())
)())()()(()(
()(())()())
)(()(())())
()(())(()))
))()(()(())(
()((()())))
)()(((())))
)())()())))
(((()()())))
()())()())()
()())(())()
)()((()())((
(()()((((())
(())))()()))
((...

output:

((()(())))()
()))()()))()
impossible
())(())))())
impossible
impossible
(()))(())())
impossible
impossible
impossible
()(())()())
)(()(())())
()(())(()))
impossible
()((()())))
)()(((())))
)())()())))
(((()()())))
()())()())()
()())(())()
impossible
impossible
(())))()()))
((((())))))
impossible
())...

result:

ok 83333 cases (83333 test cases)

Test #10:

score: 0
Accepted
time: 20ms
memory: 5796kb

input:

250000
)())
()))
())(
(())
()()
())
))((
())
)()
())
()((
()))
(())
)(((
())
(())
))()
)())
(()(
)()
((((
()))
)))(
(()(
()()
))))
)())
()()
((()
)(((
()()
(())
)(()
()()
)()
)))(
())
())(
())
)))(
))()
())
)())
))((
())
()))
((()
)()(
)()
()))
())
)())
(())
(()(
()()
()))
()))
)))(
()))
)()
())
())...

output:

)())
()))
impossible
(())
()()
())
impossible
())
)()
())
impossible
()))
(())
impossible
())
(())
))()
)())
impossible
)()
impossible
()))
impossible
impossible
()()
))))
)())
()()
impossible
impossible
()()
(())
impossible
()()
)()
impossible
())
impossible
())
impossible
))()
())
)())
impossible
...

result:

ok 250000 cases (250000 test cases)

Test #11:

score: 0
Accepted
time: 7ms
memory: 3804kb

input:

50000
(())(()(()(())))())
())()()))(())()()())
())()())((()(()))))
()(()()))(()((())))
()))))()))((()((()))
()(())())())(()))())
((()((()((())))())))
())()))()()()())))))
(((()()))))))()(())
))(()((())((((()((((
()((()()(((()()()())
(()())(()(()))())))
()()))))(()(()()()))
())()())(((()(()))))
()(((...

output:

(())(()(()(())))())
())()()))(())()()())
())()())((()(()))))
()(()()))(()((())))
impossible
()(())())())(()))())
((()((()((())))())))
())()))()()()())))))
(((()()))))))()(())
impossible
impossible
(()())(()(()))())))
()()))))(()(()()()))
())()())(((()(()))))
()((()(()))()(())))
impossible
()))())(()...

result:

ok 50000 cases (50000 test cases)

Test #12:

score: 0
Accepted
time: 13ms
memory: 5796kb

input:

83333
())()))))(()
(()((()(()))
((((((()())(
())(((((()))
((())((())))
)())())))))(
()(((())((()
()(((()))))
(()))((()))
)(())())((((
)()()()(())
)(()))(())))
)(((()())))
)(())(()()))
(())))(()))(
(((((()))))(
))((()()())(
(((()))())()
(((()()((())
())))))(((((
()((((()))))
)()(()))(())
(()))(()()))...

output:

impossible
impossible
impossible
impossible
((())((())))
impossible
impossible
()(((()))))
(()))((()))
impossible
)()()()(())
)(()))(())))
)(((()())))
)(())(()()))
impossible
impossible
impossible
(((()))())()
impossible
impossible
()((((()))))
)()(()))(())
(()))(()()))
)())))()()))
impossible
(())(...

result:

ok 83333 cases (83333 test cases)

Test #13:

score: 0
Accepted
time: 23ms
memory: 5860kb

input:

250000
(())
((((
(())
())
()()
(())
(())
())
))()
(())
))()
(())
()))
))))
(())
()))
()))
())
)()(
)))
)())
(())
(())
))()
(())
())
()))
))()
))((
)()
()()
)(((
(())
()()
)()
)(()
())
)())
((()
))()
)(((
()))
())
())
)())
()))
)())
(())
))()
))))
)())
())
))()
)()(
))))
((((
())
(())
)()
)())
())
()...

output:

(())
impossible
(())
())
()()
(())
(())
())
))()
(())
))()
(())
()))
))))
(())
()))
()))
())
impossible
)))
)())
(())
(())
))()
(())
())
()))
))()
impossible
)()
()()
impossible
(())
()()
)()
impossible
())
)())
impossible
))()
impossible
()))
())
())
)())
()))
)())
(())
))()
))))
)())
())
))()
impo...

result:

ok 250000 cases (250000 test cases)

Test #14:

score: 0
Accepted
time: 10ms
memory: 5848kb

input:

50000
))(())())())()(()(()
)((())((()()))(())))
()(()(()))()(()()))
((()())()())(()(()))
)()()(())())()(())()
(()(()(((())))()()))
((()))()()(()(()((()
()()()()(())(((())))
)))))((((()()()()(((
((())((()()(())))))
(((((()()()(()))))))
())())))())())()(())
((())((((((())))))))
((())()())())()()())
()...

output:

impossible
)((())((()()))(())))
()(()(()))()(()()))
((()())()())(()(()))
)()()(())())()(())()
(()(()(((())))()()))
impossible
()()()()(())(((())))
impossible
((())((()()(())))))
(((((()()()(()))))))
())())))())())()(())
((())((((((())))))))
((())()())())()()())
()((((()(((())))))))
()())(((()))((())...

result:

ok 50000 cases (50000 test cases)

Test #15:

score: 0
Accepted
time: 13ms
memory: 5856kb

input:

83333
)))((())(()(
()((()))())
(()))()(()((
))((()()(()(
(()))()()))
)))()()(()((
)(()))()()((
())((()))))
(())))()())
)(()()))(()(
()(()()))()
()))())())((
((()(()())))
(((())()()()
()(())(()())
))())((()))
())((()()(()
))(()((())))
((((()()))))
(()((())())(
)()())(())()
))(()())()))
(()(())(()()
(...

output:

impossible
()((()))())
impossible
impossible
(()))()()))
impossible
impossible
())((()))))
(())))()())
impossible
()(()()))()
impossible
((()(()())))
impossible
()(())(()())
))())((()))
impossible
))(()((())))
((((()()))))
impossible
)()())(())()
))(()())()))
impossible
())(())()()
impossible
imposs...

result:

ok 83333 cases (83333 test cases)

Test #16:

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

input:

1
(()()((((())))(((((((())(()())())()(()((()(((()(()))))())((())((())((()))()())(()))()))((())()())))()())()(()((())(((()()(((())(((()))(((()())((()(((()())()())(()(()(())()()())())(((((((()((((()))()())())((((()(()())()())))((()((((()(((((()((((())()(()(()((((()()(((())())())))(())))))))))((((()(()...

output:


result:

wrong answer the answer string contains illegal characters (test case 1)