QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#305632#7683. Hard Brackets Problem275307894a#WA 1ms6012kbC++141005b2024-01-15 19:00:402024-01-15 19:00:41

Judging History

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

  • [2024-01-15 19:00:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6012kb
  • [2024-01-15 19:00:40]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e6+5,M=N*20+5,K=(1<<25)+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
char s[N],ans[N];int ah,n,st[N],sh;
void Solve(){
	int i,j;scanf("%s",s+1);n=strlen(s+1);
	sh=ah=0;
	for(i=1;i<=n;i++){
		if(s[i]=='('){
			st[++sh]=i;ans[++ah]='(';
		}else{
			if(sh) sh--,ans[++ah]=')';
			else ans[++ah]=')';
		}
	}
	ans[ah+1]=0;
	if(sh) puts("-1");
	else puts(ans+1);
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 6012kb

input:

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

output:

((()))
-1
)))()

result:

wrong answer the output is too long (test case 2)