QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#614000 | #4212. Brackets | lc20110802 | WA | 1ms | 5616kb | C++14 | 723b | 2024-10-05 15:18:17 | 2024-10-05 15:20:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int n, a[N], ans[N];
signed main(){
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
if(n % 2){cout << "(" << endl; return 0;}
for(int i = 1; i <= 2 * n; i++)
cin >> a[i];
if(a[1] == a[2 * n]){cout << "(" << endl; return 0;}
ans[a[1]] = 1, ans[a[2 * n]] = -1;
int cnt = 1;
for(int i = 1; i <= 2 * n; i++){
if(ans[a[i]] != 0) continue;
cnt++; if(cnt <= n / 2) ans[a[i]] = 1;
}
int top = 0;
for(int i = 1; i <= 2 * n; i++){
top += ans[a[i]];
if(top < 0){cout << "(" << endl; return 0;}
}
for(int i = 1; i <= 2 * n; i++)
cout << (ans[a[i]] == 1 ? '(' : ')');
cout << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5604kb
input:
2 1 2 1 2
output:
()()
result:
ok single line: '()()'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
1 1 1
output:
(
result:
ok single line: '('
Test #3:
score: 0
Accepted
time: 1ms
memory: 5616kb
input:
4 4 3 1 2 3 2 1 4
output:
(
result:
ok single line: '('
Test #4:
score: 0
Accepted
time: 1ms
memory: 5612kb
input:
4 3 1 2 1 4 3 2 4
output:
(()()())
result:
ok single line: '(()()())'
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 5604kb
input:
4 2 4 3 1 3 4 2 1
output:
(()))(()
result:
wrong answer 1st lines differ - expected: '()()()()', found: '(()))(()'