QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#545445 | #7683. Hard Brackets Problem | zzz666 | WA | 142ms | 4572kb | C++20 | 737b | 2024-09-03 13:00:17 | 2024-09-03 13:00:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+4;
void slove()
{
string s;
cin>>s;
stack<char>sta;
char ans[N];
int cnt = 0 ;
for(int i = 0 ; i < s.size() ; i++)
{
if(s[i] == '(')
{
sta.push('(');
continue;
}
if(sta.empty() && s[i] == ')')
{
ans[++cnt] = ')';
continue;
}
if(!sta.empty() && s[i] == ')')
{
ans[++cnt] = '(';
sta.pop();
continue;
}
}
if(cnt == 0)
{
cout<<"impossible"<<endl;
return;
}
while(!sta.empty())
{
ans[++cnt] = sta.top();
sta.pop();
}
for(int i = 1 ; i <= cnt ; i ++ )
{
cout<<ans[i];
}
cout<<endl;
}
int main()
{
int tcase;
cin>>tcase;
while(tcase--)
{
slove();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4548kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 142ms
memory: 4572kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
()(((( (()()) )(((( ()(((( (((() )((())( )())())) )))))(((( ())((((( ((((( (((() ()(()( (((()) ))))(((( ())(((( ((((( ())())( ((((( (())((( ())(() (((() ()((( ()(((( (((() (((((( ))))()))( ((((((( (((((( )(((((( ()(()( ))((((( (((()( )()((((( )))(()( (()()( ((()() (((() )(((((( (((() )(((( (((() )((...
result:
wrong answer the result string is incorrect (test case 1)