QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#614220 | #4212. Brackets | wxy2010 | RE | 1ms | 7928kb | C++14 | 2.0kb | 2024-10-05 15:56:14 | 2024-10-05 15:56:14 |
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);
for(int i=1;i<=n*2;i++)if(!ans[i]){
int j=c[a[i]];
if(st.lower_bound(i)!=st.end()&&st.lower_bound(j)!=st.end())st.erase(st.lower_bound(i)),st.erase(st.lower_bound(j)),ans[i]='(';
else ans[i]=')';
ans[j]=ans[i];
}
if(st.empty())cout<<ans+1<<endl;
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: 7928kb
input:
2 1 2 1 2
output:
()()
result:
ok single line: '()()'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7716kb
input:
1 1 1
output:
(
result:
ok single line: '('
Test #3:
score: -100
Runtime Error
input:
4 4 3 1 2 3 2 1 4