115302024-10-19 10:50:09DávidBob Baba Zárójelsorozatacpp17Wrong answer 20/100598ms568 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);
	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);
			eredmeny = szamolas(i);
		}
	}
	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
1Accepted1ms508 KiB
2Accepted1ms320 KiB
3Accepted1ms508 KiB
subtask220/20
4Accepted1ms320 KiB
5Accepted1ms412 KiB
6Accepted1ms320 KiB
subtask30/30
7Wrong answer1ms508 KiB
8Wrong answer1ms320 KiB
9Wrong answer1ms508 KiB
10Accepted1ms320 KiB
11Wrong answer1ms320 KiB
subtask40/50
12Accepted1ms320 KiB
13Wrong answer1ms508 KiB
14Wrong answer1ms320 KiB
15Wrong answer1ms408 KiB
16Accepted1ms320 KiB
17Accepted1ms320 KiB
18Accepted1ms412 KiB
19Wrong answer1ms320 KiB
20Wrong answer1ms320 KiB
21Wrong answer1ms392 KiB
22Accepted1ms320 KiB
23Accepted1ms320 KiB
24Accepted1ms508 KiB
25Wrong answer1ms408 KiB
26Wrong answer1ms320 KiB
27Accepted1ms404 KiB
28Accepted1ms336 KiB
29Accepted1ms568 KiB
30Accepted1ms320 KiB
31Wrong answer1ms396 KiB
32Wrong answer1ms320 KiB
33Accepted1ms320 KiB
34Accepted1ms560 KiB
35Accepted1ms320 KiB
36Wrong answer1ms408 KiB
37Wrong answer1ms320 KiB
38Wrong answer1ms320 KiB
39Wrong answer1ms508 KiB
40Wrong answer1ms320 KiB
41Wrong answer1ms568 KiB
42Wrong answer1ms320 KiB
43Wrong answer1ms320 KiB
44Wrong answer1ms508 KiB
45Wrong answer1ms568 KiB
46Wrong answer1ms320 KiB
47Wrong answer1ms512 KiB
48Wrong answer1ms320 KiB
49Wrong answer1ms320 KiB
50Wrong answer1ms408 KiB
51Wrong answer1ms320 KiB
52Wrong answer1ms404 KiB
53Time limit exceeded598ms320 KiB
54Time limit exceeded598ms320 KiB
55Wrong answer1ms320 KiB
56Wrong answer1ms320 KiB
57Wrong answer1ms320 KiB
58Wrong answer1ms320 KiB