11595 | 2024-10-29 19:25:40 | Dávid | Bob Baba Zárójelsorozata | cpp17 | Wrong answer 0/100 | 170ms | 6712 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 1ms | 320 KiB | ||||
2 | Accepted | 1ms | 500 KiB | ||||
3 | Wrong answer | 1ms | 532 KiB | ||||
subtask2 | 0/20 | ||||||
4 | Wrong answer | 2ms | 320 KiB | ||||
5 | Wrong answer | 2ms | 568 KiB | ||||
6 | Accepted | 1ms | 320 KiB | ||||
subtask3 | 0/30 | ||||||
7 | Accepted | 1ms | 508 KiB | ||||
8 | Accepted | 1ms | 320 KiB | ||||
9 | Accepted | 1ms | 320 KiB | ||||
10 | Wrong answer | 1ms | 508 KiB | ||||
11 | Accepted | 1ms | 320 KiB | ||||
subtask4 | 0/50 | ||||||
12 | Wrong answer | 168ms | 6588 KiB | ||||
13 | Accepted | 166ms | 6580 KiB | ||||
14 | Accepted | 168ms | 6712 KiB | ||||
15 | Accepted | 168ms | 6580 KiB | ||||
16 | Wrong answer | 166ms | 6712 KiB | ||||
17 | Wrong answer | 170ms | 6708 KiB | ||||
18 | Wrong answer | 85ms | 3828 KiB | ||||
19 | Accepted | 86ms | 3640 KiB | ||||
20 | Accepted | 86ms | 3640 KiB | ||||
21 | Accepted | 86ms | 3500 KiB | ||||
22 | Wrong answer | 82ms | 3384 KiB | ||||
23 | Wrong answer | 85ms | 3572 KiB | ||||
24 | Wrong answer | 35ms | 1592 KiB | ||||
25 | Accepted | 35ms | 1780 KiB | ||||
26 | Accepted | 35ms | 1592 KiB | ||||
27 | Wrong answer | 35ms | 1592 KiB | ||||
28 | Wrong answer | 34ms | 1624 KiB | ||||
29 | Wrong answer | 34ms | 1656 KiB | ||||
30 | Wrong answer | 17ms | 1028 KiB | ||||
31 | Accepted | 17ms | 1040 KiB | ||||
32 | Accepted | 17ms | 1024 KiB | ||||
33 | Wrong answer | 17ms | 1032 KiB | ||||
34 | Wrong answer | 17ms | 1016 KiB | ||||
35 | Wrong answer | 18ms | 1032 KiB | ||||
36 | Accepted | 16ms | 912 KiB | ||||
37 | Accepted | 9ms | 824 KiB | ||||
38 | Accepted | 16ms | 1076 KiB | ||||
39 | Accepted | 25ms | 1216 KiB | ||||
40 | Accepted | 32ms | 1408 KiB | ||||
41 | Accepted | 32ms | 1592 KiB | ||||
42 | Accepted | 35ms | 1528 KiB | ||||
43 | Accepted | 32ms | 1484 KiB | ||||
44 | Accepted | 46ms | 1928 KiB | ||||
45 | Accepted | 46ms | 2108 KiB | ||||
46 | Accepted | 64ms | 2872 KiB | ||||
47 | Accepted | 64ms | 2872 KiB | ||||
48 | Accepted | 68ms | 2916 KiB | ||||
49 | Accepted | 71ms | 3180 KiB | ||||
50 | Accepted | 79ms | 3384 KiB | ||||
51 | Accepted | 104ms | 4328 KiB | ||||
52 | Accepted | 109ms | 4920 KiB | ||||
53 | Accepted | 115ms | 5284 KiB | ||||
54 | Accepted | 136ms | 6196 KiB | ||||
55 | Accepted | 162ms | 6352 KiB | ||||
56 | Accepted | 134ms | 5312 KiB | ||||
57 | Accepted | 100ms | 4108 KiB | ||||
58 | Accepted | 105ms | 4424 KiB |