QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#616561 | #4212. Brackets | ucup-team3659 | WA | 1ms | 5588kb | C++20 | 1.9kb | 2024-10-06 08:00:01 | 2024-10-06 08:00:01 |
Judging History
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: 5588kb
input:
2 1 2 1 2
output:
()()
result:
ok single line: '()()'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5548kb
input:
1 1 1
output:
:(
result:
wrong answer 1st lines differ - expected: '(', found: ':('