9111 | 2024-02-14 16:19:45 | 111 | Bob Baba Zárójelsorozata | cpp17 | Accepted 100/100 | 8ms | 10976 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifdef CB
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
int N;
cin >> N;
vector<int> v(N);
for (int i = 0; i < N; i++) {
cin >> v[i];
}
vector<bitset<50001>> b(N + 1);
b[0][0] = 1;
for (int i = 0; i < N; i++) {
b[i + 1] = b[i] << v[i] | b[i] >> v[i];
}
if (!b[N][0]) {
cout << -1 << '\n';
return 0;
}
string ans;
int y = 0;
for (int i = N - 1; i >= 0; i--) {
if (b[i][y + v[i]]) {
y += v[i];
ans += string(v[i], ')');
}
else {
y -= v[i];
ans += string(v[i], '(');
}
}
reverse(ans.begin(), ans.end());
cout << ans << '\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 2000 KiB | ||||
2 | Accepted | 3ms | 2200 KiB | ||||
3 | Accepted | 3ms | 2480 KiB | ||||
subtask2 | 20/20 | ||||||
4 | Accepted | 3ms | 2736 KiB | ||||
5 | Accepted | 3ms | 2844 KiB | ||||
6 | Accepted | 3ms | 3068 KiB | ||||
subtask3 | 30/30 | ||||||
7 | Accepted | 3ms | 3316 KiB | ||||
8 | Accepted | 3ms | 3604 KiB | ||||
9 | Accepted | 3ms | 3820 KiB | ||||
10 | Accepted | 3ms | 3712 KiB | ||||
11 | Accepted | 3ms | 3856 KiB | ||||
subtask4 | 50/50 | ||||||
12 | Accepted | 8ms | 9724 KiB | ||||
13 | Accepted | 7ms | 10108 KiB | ||||
14 | Accepted | 7ms | 10224 KiB | ||||
15 | Accepted | 7ms | 10400 KiB | ||||
16 | Accepted | 7ms | 10000 KiB | ||||
17 | Accepted | 7ms | 10316 KiB | ||||
18 | Accepted | 4ms | 7092 KiB | ||||
19 | Accepted | 4ms | 7436 KiB | ||||
20 | Accepted | 4ms | 7724 KiB | ||||
21 | Accepted | 4ms | 7544 KiB | ||||
22 | Accepted | 4ms | 7112 KiB | ||||
23 | Accepted | 4ms | 7116 KiB | ||||
24 | Accepted | 4ms | 5480 KiB | ||||
25 | Accepted | 4ms | 5780 KiB | ||||
26 | Accepted | 4ms | 5752 KiB | ||||
27 | Accepted | 3ms | 5604 KiB | ||||
28 | Accepted | 4ms | 5708 KiB | ||||
29 | Accepted | 3ms | 5644 KiB | ||||
30 | Accepted | 3ms | 4996 KiB | ||||
31 | Accepted | 3ms | 5384 KiB | ||||
32 | Accepted | 3ms | 5472 KiB | ||||
33 | Accepted | 3ms | 4968 KiB | ||||
34 | Accepted | 3ms | 4884 KiB | ||||
35 | Accepted | 3ms | 4820 KiB | ||||
36 | Accepted | 3ms | 5296 KiB | ||||
37 | Accepted | 3ms | 5180 KiB | ||||
38 | Accepted | 3ms | 5504 KiB | ||||
39 | Accepted | 3ms | 5748 KiB | ||||
40 | Accepted | 3ms | 5968 KiB | ||||
41 | Accepted | 4ms | 6184 KiB | ||||
42 | Accepted | 4ms | 6052 KiB | ||||
43 | Accepted | 4ms | 6192 KiB | ||||
44 | Accepted | 4ms | 6468 KiB | ||||
45 | Accepted | 4ms | 6684 KiB | ||||
46 | Accepted | 4ms | 7248 KiB | ||||
47 | Accepted | 4ms | 7276 KiB | ||||
48 | Accepted | 4ms | 7472 KiB | ||||
49 | Accepted | 4ms | 7696 KiB | ||||
50 | Accepted | 4ms | 8132 KiB | ||||
51 | Accepted | 4ms | 9072 KiB | ||||
52 | Accepted | 6ms | 9752 KiB | ||||
53 | Accepted | 6ms | 9932 KiB | ||||
54 | Accepted | 7ms | 10704 KiB | ||||
55 | Accepted | 7ms | 10976 KiB | ||||
56 | Accepted | 6ms | 9940 KiB | ||||
57 | Accepted | 4ms | 8844 KiB | ||||
58 | Accepted | 4ms | 8948 KiB |