75142024-01-09 12:04:38rennBob Baba Zárójelsorozatacpp17Wrong answer 20/1003ms5104 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 << endl;

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

    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2060 KiB
3Accepted3ms2280 KiB
subtask220/20
4Accepted3ms2500 KiB
5Accepted3ms2704 KiB
6Accepted3ms3076 KiB
subtask30/30
7Wrong answer2ms2960 KiB
8Wrong answer3ms2972 KiB
9Wrong answer2ms2964 KiB
10Accepted3ms2968 KiB
11Wrong answer3ms3080 KiB
subtask40/50
12Accepted3ms3308 KiB
13Wrong answer3ms3516 KiB
14Wrong answer3ms3632 KiB
15Wrong answer3ms4000 KiB
16Accepted3ms3904 KiB
17Accepted3ms3920 KiB
18Accepted3ms4128 KiB
19Wrong answer3ms4140 KiB
20Wrong answer3ms4128 KiB
21Wrong answer3ms4248 KiB
22Accepted3ms4256 KiB
23Accepted3ms4232 KiB
24Accepted2ms4232 KiB
25Wrong answer3ms4228 KiB
26Wrong answer3ms4360 KiB
27Accepted3ms4588 KiB
28Accepted3ms4596 KiB
29Accepted3ms4584 KiB
30Accepted3ms4588 KiB
31Wrong answer3ms4584 KiB
32Wrong answer3ms4580 KiB
33Accepted3ms4716 KiB
34Accepted2ms4796 KiB
35Accepted2ms4796 KiB
36Wrong answer2ms4796 KiB
37Wrong answer3ms4792 KiB
38Wrong answer3ms4792 KiB
39Wrong answer2ms4900 KiB
40Wrong answer2ms4896 KiB
41Wrong answer3ms5032 KiB
42Wrong answer2ms4796 KiB
43Wrong answer3ms4796 KiB
44Wrong answer2ms4940 KiB
45Wrong answer2ms4792 KiB
46Wrong answer3ms4796 KiB
47Wrong answer2ms4892 KiB
48Wrong answer3ms4800 KiB
49Wrong answer3ms4896 KiB
50Wrong answer3ms4996 KiB
51Wrong answer3ms4896 KiB
52Wrong answer3ms4956 KiB
53Wrong answer3ms4824 KiB
54Wrong answer3ms4804 KiB
55Wrong answer3ms5016 KiB
56Wrong answer3ms4956 KiB
57Wrong answer3ms5012 KiB
58Wrong answer3ms5104 KiB