QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#555243#7683. Hard Brackets Problemprime-idealWA 40ms3672kbC++201.1kb2024-09-09 20:59:052024-09-09 20:59:06

Judging History

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

  • [2024-09-09 20:59:06]
  • 评测
  • 测评结果:WA
  • 用时:40ms
  • 内存:3672kb
  • [2024-09-09 20:59:05]
  • 提交

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)