91112024-02-14 16:19:45111Bob Baba Zárójelsorozatacpp17Accepted 100/1008ms10976 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2000 KiB
2Accepted3ms2200 KiB
3Accepted3ms2480 KiB
subtask220/20
4Accepted3ms2736 KiB
5Accepted3ms2844 KiB
6Accepted3ms3068 KiB
subtask330/30
7Accepted3ms3316 KiB
8Accepted3ms3604 KiB
9Accepted3ms3820 KiB
10Accepted3ms3712 KiB
11Accepted3ms3856 KiB
subtask450/50
12Accepted8ms9724 KiB
13Accepted7ms10108 KiB
14Accepted7ms10224 KiB
15Accepted7ms10400 KiB
16Accepted7ms10000 KiB
17Accepted7ms10316 KiB
18Accepted4ms7092 KiB
19Accepted4ms7436 KiB
20Accepted4ms7724 KiB
21Accepted4ms7544 KiB
22Accepted4ms7112 KiB
23Accepted4ms7116 KiB
24Accepted4ms5480 KiB
25Accepted4ms5780 KiB
26Accepted4ms5752 KiB
27Accepted3ms5604 KiB
28Accepted4ms5708 KiB
29Accepted3ms5644 KiB
30Accepted3ms4996 KiB
31Accepted3ms5384 KiB
32Accepted3ms5472 KiB
33Accepted3ms4968 KiB
34Accepted3ms4884 KiB
35Accepted3ms4820 KiB
36Accepted3ms5296 KiB
37Accepted3ms5180 KiB
38Accepted3ms5504 KiB
39Accepted3ms5748 KiB
40Accepted3ms5968 KiB
41Accepted4ms6184 KiB
42Accepted4ms6052 KiB
43Accepted4ms6192 KiB
44Accepted4ms6468 KiB
45Accepted4ms6684 KiB
46Accepted4ms7248 KiB
47Accepted4ms7276 KiB
48Accepted4ms7472 KiB
49Accepted4ms7696 KiB
50Accepted4ms8132 KiB
51Accepted4ms9072 KiB
52Accepted6ms9752 KiB
53Accepted6ms9932 KiB
54Accepted7ms10704 KiB
55Accepted7ms10976 KiB
56Accepted6ms9940 KiB
57Accepted4ms8844 KiB
58Accepted4ms8948 KiB