115312024-10-19 11:35:47DávidBob Baba Zárójelsorozatacpp17Wrong answer 20/100587ms544 KiB
#include <bits/stdc++.h>
#include <utility>
#include <vector>
using namespace std;

int n;
vector<long long> prefix;

vector<pair<int, int>> szamolas(int b) {
	vector<pair<int, int>> eredmeny;
	pair<int, int> par = pair<int, int>(-1, -1);
	if(b >= n) par = pair<int, int>(0, 0);
	bool jo = false;
	int j = b + 1;
	for(int i = b + 2; i <= n; i++) {
		while(prefix[j] - prefix[b] < prefix[i] - prefix[j]) {
			j++;
		}
		if(prefix[j] - prefix[b] == prefix[i] - prefix[j]) {
			par = pair<int, int>(j, i);
			vector<pair<int, int>> v = szamolas(i);
			if(v[0].first > -1) {
				eredmeny = v;
				jo = true;
			}
		}
	}
	eredmeny.push_back(par);
	return eredmeny;
}

int main() {
	cin >> n;

	prefix.resize(n + 1);

	for(int i = 1; i <= n; i++) {
		cin >> prefix[i];
		prefix[i] += prefix[i - 1];
	}

	vector<pair<int, int>> eredmeny = szamolas(0);
	if(eredmeny[0].first == -1) {
		cout << -1 << endl;
		return 0;
	}
	reverse(eredmeny.begin(), eredmeny.end());

	int j = 0;
	for(long long i = 1; i <= prefix[n]; i++) {
		if(i <= prefix[eredmeny[j].first]) {
			cout << "(";
		} else if(i <= prefix[eredmeny[j].second]) {
			cout << ")";
		} else {
			j++;
			cout << "(";
		}
	}
	cout << endl;
	
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms320 KiB
2Accepted1ms320 KiB
3Accepted1ms320 KiB
subtask220/20
4Accepted1ms320 KiB
5Accepted1ms508 KiB
6Accepted1ms320 KiB
subtask30/30
7Wrong answer1ms320 KiB
8Wrong answer1ms320 KiB
9Wrong answer1ms320 KiB
10Wrong answer1ms320 KiB
11Wrong answer1ms320 KiB
subtask40/50
12Accepted1ms320 KiB
13Runtime error3ms320 KiB
14Runtime error3ms320 KiB
15Runtime error3ms320 KiB
16Runtime error3ms424 KiB
17Accepted1ms320 KiB
18Accepted1ms320 KiB
19Wrong answer1ms320 KiB
20Wrong answer1ms320 KiB
21Wrong answer1ms320 KiB
22Runtime error1ms320 KiB
23Accepted1ms320 KiB
24Accepted1ms320 KiB
25Wrong answer1ms324 KiB
26Wrong answer1ms500 KiB
27Accepted1ms320 KiB
28Accepted1ms324 KiB
29Accepted1ms320 KiB
30Accepted1ms320 KiB
31Wrong answer1ms320 KiB
32Wrong answer1ms320 KiB
33Accepted1ms320 KiB
34Accepted1ms320 KiB
35Accepted1ms320 KiB
36Wrong answer1ms320 KiB
37Wrong answer1ms320 KiB
38Wrong answer1ms320 KiB
39Wrong answer1ms320 KiB
40Wrong answer1ms320 KiB
41Runtime error3ms440 KiB
42Wrong answer1ms332 KiB
43Wrong answer1ms500 KiB
44Wrong answer1ms544 KiB
45Wrong answer1ms500 KiB
46Wrong answer1ms320 KiB
47Runtime error1ms500 KiB
48Runtime error1ms320 KiB
49Runtime error3ms320 KiB
50Runtime error1ms320 KiB
51Runtime error1ms320 KiB
52Runtime error1ms320 KiB
53Time limit exceeded587ms320 KiB
54Time limit exceeded583ms508 KiB
55Runtime error3ms320 KiB
56Runtime error3ms408 KiB
57Runtime error2ms320 KiB
58Runtime error3ms320 KiB