75102024-01-09 11:55:40rennBob Baba Zárójelsorozatacpp17Wrong answer 0/1003ms5392 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n;
    cin >> n;

    vector<int> a(n);
    string s;

    for(auto &x : a)
        cin >> x;
    a.push_back(0);

    int nyit = 0, zar = 0;
    bool zarat_keres = false;

    for(int i = 0, j, k; i < n; i++)
    {
        nyit += a[i];
        zar = 0;
        for(j = i+1; j < n; j++)
        {
            zar += a[j];
            if(nyit == zar) // bezárható
            {
                for(k = 0; k < nyit; k++)
                    s += '(';
                for(k = 0; k < nyit; k++)
                    s += ')';
                i = j;
                nyit = 0;
                break;
            }

            if(nyit < zar) // túlmentem
                break;

            // még nem értem el, megyek tovább...
        }
    }

    cout << ((nyit == zar) ? s : "-1") << "\n";

    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1976 KiB
2Wrong answer3ms2008 KiB
3Accepted3ms2348 KiB
subtask20/20
4Accepted2ms2436 KiB
5Accepted3ms2540 KiB
6Wrong answer3ms2940 KiB
subtask30/30
7Wrong answer3ms2856 KiB
8Wrong answer3ms2936 KiB
9Wrong answer3ms3080 KiB
10Accepted3ms3164 KiB
11Wrong answer3ms3356 KiB
subtask40/50
12Accepted3ms3572 KiB
13Wrong answer3ms4032 KiB
14Wrong answer3ms4228 KiB
15Wrong answer3ms4248 KiB
16Accepted3ms4248 KiB
17Accepted3ms4012 KiB
18Accepted3ms4136 KiB
19Wrong answer3ms4244 KiB
20Wrong answer3ms4292 KiB
21Wrong answer3ms4272 KiB
22Accepted3ms4512 KiB
23Accepted3ms4492 KiB
24Accepted3ms4584 KiB
25Wrong answer3ms4960 KiB
26Wrong answer3ms4744 KiB
27Accepted3ms4716 KiB
28Accepted3ms4712 KiB
29Accepted3ms4708 KiB
30Accepted3ms4728 KiB
31Wrong answer3ms4820 KiB
32Wrong answer3ms4912 KiB
33Accepted3ms4916 KiB
34Accepted3ms4816 KiB
35Accepted3ms4820 KiB
36Wrong answer3ms4812 KiB
37Wrong answer3ms4816 KiB
38Wrong answer3ms4936 KiB
39Wrong answer3ms4908 KiB
40Wrong answer3ms4940 KiB
41Wrong answer3ms5256 KiB
42Wrong answer3ms5016 KiB
43Wrong answer3ms5016 KiB
44Wrong answer3ms5012 KiB
45Wrong answer3ms5160 KiB
46Wrong answer3ms5124 KiB
47Wrong answer3ms5220 KiB
48Wrong answer3ms5124 KiB
49Wrong answer3ms5012 KiB
50Wrong answer3ms5140 KiB
51Wrong answer3ms5160 KiB
52Wrong answer3ms5160 KiB
53Wrong answer3ms5160 KiB
54Wrong answer3ms5160 KiB
55Wrong answer3ms5220 KiB
56Wrong answer3ms5388 KiB
57Wrong answer3ms5208 KiB
58Wrong answer3ms5392 KiB