117212024-11-07 17:11:12hunzombiBob Baba Zárójelsorozatacpp14Wrong answer 0/1001ms560 KiB
#include <bits/stdc++.h>

using namespace std;

int N;
int x;
int values[501];
bitset<50001> dp[502];

int main()
{
    ifstream cin("input.txt");
    ofstream cout("output.txt");

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;

    cin >> x;
    dp[1][x] = 1;
    values[1] = x;

    for (int i=2; i <= N; i++) {
        cin >> x;
        values[i] = x;
        for (int j=0; j < 50001; j++){
            if (dp[i - 1][j] == 1){
                if (j - x >= 0){
                    dp[i][j - x] = 1;
                }
                if (j + x <= 50000){
                    dp[i][j + x] = 1;
                }
            }
        }
    }

    if (dp[N][0] == 0){
        cout << -1;
        return 0;
    }

    string res = "";
    int j = 0;
    for (int i = N; i >= 1; i--){
        if (((j - values[i] >= 0 && dp[i - 1][j - values[i]] == 1) || (i == 1)) && i != N){
            j = j - values[i];
            for (int k=0; k < values[i]; k++){
                res = "(" + res;
            }
        } else {
            j = j + values[i];
            for (int k=0; k < values[i]; k++){
                res = ")" + res;
            }
        }
    }

    cout << res;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer1ms320 KiB
2Wrong answer1ms508 KiB
3Wrong answer1ms320 KiB
subtask20/20
4Wrong answer1ms320 KiB
5Wrong answer1ms320 KiB
6Wrong answer1ms320 KiB
subtask30/30
7Wrong answer1ms320 KiB
8Wrong answer1ms320 KiB
9Wrong answer1ms320 KiB
10Wrong answer1ms320 KiB
11Wrong answer1ms320 KiB
subtask40/50
12Wrong answer1ms320 KiB
13Wrong answer1ms320 KiB
14Wrong answer1ms320 KiB
15Wrong answer1ms320 KiB
16Wrong answer1ms320 KiB
17Wrong answer1ms508 KiB
18Wrong answer1ms320 KiB
19Wrong answer1ms508 KiB
20Wrong answer1ms500 KiB
21Wrong answer1ms560 KiB
22Wrong answer1ms320 KiB
23Wrong answer1ms508 KiB
24Wrong answer1ms320 KiB
25Wrong answer1ms508 KiB
26Wrong answer1ms320 KiB
27Wrong answer1ms320 KiB
28Wrong answer1ms320 KiB
29Wrong answer1ms384 KiB
30Wrong answer1ms508 KiB
31Wrong answer1ms508 KiB
32Wrong answer1ms508 KiB
33Wrong answer1ms320 KiB
34Wrong answer1ms508 KiB
35Wrong answer1ms404 KiB
36Wrong answer1ms536 KiB
37Wrong answer1ms320 KiB
38Wrong answer1ms320 KiB
39Wrong answer1ms320 KiB
40Wrong answer1ms320 KiB
41Wrong answer1ms320 KiB
42Wrong answer1ms320 KiB
43Wrong answer1ms320 KiB
44Wrong answer1ms320 KiB
45Wrong answer1ms500 KiB
46Wrong answer1ms320 KiB
47Wrong answer1ms320 KiB
48Wrong answer1ms320 KiB
49Wrong answer1ms500 KiB
50Wrong answer1ms320 KiB
51Wrong answer1ms320 KiB
52Wrong answer1ms320 KiB
53Wrong answer1ms324 KiB
54Wrong answer1ms324 KiB
55Wrong answer1ms408 KiB
56Wrong answer1ms320 KiB
57Wrong answer1ms320 KiB
58Wrong answer1ms320 KiB