115952024-10-29 19:25:40DávidBob Baba Zárójelsorozatacpp17Wrong answer 0/100170ms6712 KiB
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
using namespace std;

#define ll long long

int main() {
	int n;
	cin >> n;

	ll osszeg = 0;
	vector<int> szamok(n + 1);

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

	vector<vector<bool>> dp(n + 1, vector<bool>(osszeg + 1));
	dp[0][0] = true;
	vector<vector<bool>> vissza(n + 1, vector<bool>(osszeg + 1));
	
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < osszeg; j++) {
			if(j - szamok[i] >= 0 && dp[i - 1][j - szamok[i]]) {
				dp[i][j] = true;
				vissza[i][j] = 0;
			}
			if(j + szamok[i] <= osszeg && dp[i - 1][j + szamok[i]]) {
				dp[i][j] = true;
				vissza[i][j] = 1;
			}
		}
	}

	vector<char> eredmeny;
	int j = 0;
	for(int i = n; i > 0; i--) {
		if(!vissza[i][j]) {
			for(int k = 0; k < szamok[i]; k++) eredmeny.push_back('(');
			j -= szamok[i];
		} else {
			for(int k = 0; k < szamok[i]; k++) eredmeny.push_back(')');
			j += szamok[i];
		}
	}
	reverse(eredmeny.begin(), eredmeny.end());
	for(char i : eredmeny) {
		cout << i;
	}

	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms320 KiB
2Accepted1ms500 KiB
3Wrong answer1ms532 KiB
subtask20/20
4Wrong answer2ms320 KiB
5Wrong answer2ms568 KiB
6Accepted1ms320 KiB
subtask30/30
7Accepted1ms508 KiB
8Accepted1ms320 KiB
9Accepted1ms320 KiB
10Wrong answer1ms508 KiB
11Accepted1ms320 KiB
subtask40/50
12Wrong answer168ms6588 KiB
13Accepted166ms6580 KiB
14Accepted168ms6712 KiB
15Accepted168ms6580 KiB
16Wrong answer166ms6712 KiB
17Wrong answer170ms6708 KiB
18Wrong answer85ms3828 KiB
19Accepted86ms3640 KiB
20Accepted86ms3640 KiB
21Accepted86ms3500 KiB
22Wrong answer82ms3384 KiB
23Wrong answer85ms3572 KiB
24Wrong answer35ms1592 KiB
25Accepted35ms1780 KiB
26Accepted35ms1592 KiB
27Wrong answer35ms1592 KiB
28Wrong answer34ms1624 KiB
29Wrong answer34ms1656 KiB
30Wrong answer17ms1028 KiB
31Accepted17ms1040 KiB
32Accepted17ms1024 KiB
33Wrong answer17ms1032 KiB
34Wrong answer17ms1016 KiB
35Wrong answer18ms1032 KiB
36Accepted16ms912 KiB
37Accepted9ms824 KiB
38Accepted16ms1076 KiB
39Accepted25ms1216 KiB
40Accepted32ms1408 KiB
41Accepted32ms1592 KiB
42Accepted35ms1528 KiB
43Accepted32ms1484 KiB
44Accepted46ms1928 KiB
45Accepted46ms2108 KiB
46Accepted64ms2872 KiB
47Accepted64ms2872 KiB
48Accepted68ms2916 KiB
49Accepted71ms3180 KiB
50Accepted79ms3384 KiB
51Accepted104ms4328 KiB
52Accepted109ms4920 KiB
53Accepted115ms5284 KiB
54Accepted136ms6196 KiB
55Accepted162ms6352 KiB
56Accepted134ms5312 KiB
57Accepted100ms4108 KiB
58Accepted105ms4424 KiB