QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#616560 | #4212. Brackets | ucup-team3659 | WA | 1ms | 7696kb | C++20 | 2.2kb | 2024-10-06 07:59:36 | 2024-10-06 07:59:36 |
Judging History
answer
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define _GLIBCXX_DEBUG_PEDANTIC
#endif
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
#define min(args...) min({args})
#define max(args...) max({args})
#define redirect(filename) freopen(#filename".in", "r", stdin), freopen(#filename".out", "w", stdout)
#define all(container) container.begin(), container.end()
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define pb push_back
#define eb emplace_back
#ifdef DEBUG
#define debug() fprintf(stderr, "%d\n", __LINE__)
#define debugf(fmt, args...) fprintf(stderr, fmt, ## args)
#define debuglf(fmt, args...) fprintf(stderr, "%d: " fmt "\n", __LINE__, ## args)
#else
#define debug()
#define debugf(...)
#define debuglf(...)
#endif
template<typename t> class gpq : public priority_queue<t, vector<t>, greater<t>> {};
typedef int64_t ll;
typedef uint64_t ull;
typedef __int128 lll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
const bool MULTIPLE_TESTS = 0;
int n,a[2002000];
int b[1001000],c[1001000];
char ans[2002000];
void solve(int _Tid) {
cin>>n;
for(int i=1;i<=n*2;i++){
cin>>a[i];
if(b[a[i]])c[a[i]]=i;
else b[a[i]]=i;
}
set<int>st;
for(int i=1;i<=n;i++)st.insert(i*2-1);
auto try_erase=[&](int x)->int{
auto tmp=st.lower_bound(x);
int tmpp=*tmp;
if(tmp!=st.end())return st.erase(tmp),tmpp;
else return 0;
};
for(int i=1;i<=n*2;i++)if(!ans[i]){
int j=c[a[i]];
if(int tmp=try_erase(i);tmp){
if(try_erase(j))ans[i]=ans[j]='(';
else st.insert(tmp),ans[i]=ans[j]=')';
}else ans[i]=ans[j]=')';
ans[j]=ans[i];
}
if(st.empty())cout<<ans+1;
else cout<<":(";
}
signed main() {
#ifndef DEBUG
fastio;
#endif
#ifdef DEBUG
auto _Tbe = chrono::steady_clock::now();
#endif
int T = 1;
if (MULTIPLE_TESTS) cin >> T;
for (int _ = 1; _ <= T; _++) solve(_);
#ifdef DEBUG
auto _Ted = chrono::steady_clock::now();
debugf("Used time: %lldms\n", chrono::duration_cast<chrono::milliseconds>(_Ted - _Tbe).count());
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7692kb
input:
2 1 2 1 2
output:
()()
result:
ok single line: '()()'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 7696kb
input:
1 1 1
output:
:(
result:
wrong answer 1st lines differ - expected: '(', found: ':('