QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#555243 | #7683. Hard Brackets Problem | prime-ideal | WA | 40ms | 3672kb | C++20 | 1.1kb | 2024-09-09 20:59:05 | 2024-09-09 20:59:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define RN return
#define forw(_,l,r) for(auto _=(l);_<(r);++_)
#define fors(_,r,l) for(auto _=(r);_>(l);--_)
// #define DEBUG if((cout<<"line:"<<__LINE__<<'\n'), 1)
#define DEBUG if(0)
// #define int ll
#define fastio cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
void read(){}
template<typename T,typename...Types>
void read(T& x, Types&...args){
x=0; char c=' '; bool sgn=0;
while(isspace(c))c=getchar();
if(c=='-')c=getchar(),sgn=1;
while(isdigit(c))x=10*x+c-'0',c=getchar();
if(sgn)x=-x;
read(args...);
}
const int NUM=1e6+100;
char str[NUM]={};
bool check(char* s){
int e=strlen(s)-1,b=0;
while(s[b]==')')++b;
if(s[b]==0)RN 1;
while(s[e]==')')--e;
++e;
int sum=0;
forw(i,b,e){
if(s[i]=='(')++sum;
else --sum;
if(sum<0)RN 0;
}
for(int i=e;str[i];++i)
if(s[i]==')')--sum;
if(sum>0)RN 0;
RN 1;
}
int main()
{
int t; cin>>t;
while(t--){
cin>>str;
bool flag=check(str);
if(!flag)cout<<"impossible\n";
else cout<<str<<endl;
}
RN 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
3 ((())) ( )))()
output:
((())) impossible )))()
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 40ms
memory: 3672kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
impossible impossible )()()()() impossible ((())())) impossible impossible impossible impossible ()((()())) (()())()) impossible (())(()))) impossible impossible ()((())()) impossible ()((())()) impossible impossible (()(()))) impossible impossible (()(()))) impossible impossible impossible impossib...
result:
wrong answer Jury has the answer but participant has not (test case 2)