QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#613958 | #4212. Brackets | lc20110802 | WA | 1ms | 5608kb | C++14 | 726b | 2024-10-05 15:10:34 | 2024-10-05 15:14:29 |
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: 5608kb
input:
2 1 2 1 2
output:
()()
result:
ok single line: '()()'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3636kb
input:
1 1 1
output:
:(
result:
wrong answer 1st lines differ - expected: '(', found: ':('