QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#616611#4212. BracketsfangzichangWA 1ms7676kbC++171.9kb2024-10-06 09:07:342024-10-06 09:07:35

Judging History

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

  • [2024-10-06 09:07:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7676kb
  • [2024-10-06 09:07:34]
  • 提交

answer

#include<bits/extc++.h>
#include<bits/stdc++.h>
//#pragma GCC optimize(2)
//This code contains niche emotional elements. It is recommended to watch it after the age of 18.
#ifdef __unix__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#else
#define getchar _getchar_nolock
#define putchar _putchar_nolock
#endif
#define debug(x) fprintf(stderr,"Line %d,%s=%lld\n",__LINE__,#x,(ll)x)
#define debugline fprintf(stderr,"--------------------------\n")
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define Inf (int)INFINITY
#define inf 0x3f3f3f3f
#define pb push_back
#define ll long long
#define endl '\n'
#define y second
#define x first
using namespace std;
const int N=2e6+10;
void read(){};
template<class T1,class...T2>
inline void read(T1&ret,T2&...rest){
	ret=0;char c=getchar();bool f=false;
	while(c<'0'||c>'9')f=c=='-',c=getchar();
	while(c>='0'&&c<='9')ret=ret*10+c-'0',c=getchar();
	f&&(ret=-ret),read(rest...);
}
#define cin(...) read(__VA_ARGS__)
template<class T>
inline void print(T x){
	static int s[35],t=0;
	bool f=x<0;if(f)x=-x;
	do s[t++]=x%10,x/=10;while(x);
	f&&putchar('-');while(t)putchar(s[--t]+'0');
}
int n,p[N],q[N][2];
char res[N];
set<int>st;
int main(){
	cin(n);
	for(int i=1;i<=n*2;i++)
		cin(p[i]),q[p[i]][(bool)q[p[i]][0]]=i;
	for(int i=1;i<=n*2;i+=2)st.insert(i);
	for(int i=1;i<=n*2;i++){
		if(i==q[p[i]][1])continue;
		auto it=st.lower_bound(q[p[i]][1]);
		if(it==st.end())
			res[i]=res[q[p[i]][1]]=')';
		else{
			auto it2=st.lower_bound(i);
			if(it==it2)it++;
			if(it==st.end())
				res[i]=res[q[p[i]][1]]=')';
			else
				res[i]=res[q[p[i]][1]]='(',
				st.erase(it),st.erase(it2);
		}
	}
	int ct=0;
	for(int i=1;i<=n*2;i++)
		if((res[i]=='('?++ct:--ct)<0)return puts(":("),0;
	if(ct)return puts("("),0;
	for(int i=1;i<=n*2;i++)
		putchar(res[i]);
	putchar(endl);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7676kb

input:

2
1 2 1 2

output:

()()

result:

ok single line: '()()'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5652kb

input:

1
1 1

output:

:(

result:

wrong answer 1st lines differ - expected: '(', found: ':('