75112024-01-09 11:59:06rennBob Baba Zárójelsorozatacpp17Wrong answer 20/1003ms4724 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
1Accepted3ms1832 KiB
2Accepted3ms2172 KiB
3Accepted3ms2392 KiB
subtask220/20
4Accepted3ms2428 KiB
5Accepted3ms2804 KiB
6Accepted3ms3044 KiB
subtask30/30
7Wrong answer3ms3220 KiB
8Wrong answer3ms3184 KiB
9Wrong answer3ms3188 KiB
10Accepted3ms3308 KiB
11Wrong answer3ms3396 KiB
subtask40/50
12Accepted3ms3400 KiB
13Wrong answer3ms3640 KiB
14Wrong answer3ms3500 KiB
15Wrong answer3ms3608 KiB
16Accepted3ms3752 KiB
17Accepted3ms3668 KiB
18Accepted3ms3868 KiB
19Wrong answer3ms3928 KiB
20Wrong answer3ms3912 KiB
21Wrong answer3ms3912 KiB
22Accepted3ms3960 KiB
23Accepted3ms4044 KiB
24Accepted2ms4128 KiB
25Wrong answer2ms4128 KiB
26Wrong answer3ms4132 KiB
27Accepted3ms4192 KiB
28Accepted3ms4292 KiB
29Accepted3ms4388 KiB
30Accepted3ms4188 KiB
31Wrong answer3ms4188 KiB
32Wrong answer3ms4192 KiB
33Accepted3ms4192 KiB
34Accepted3ms4192 KiB
35Accepted3ms4292 KiB
36Wrong answer3ms4480 KiB
37Wrong answer3ms4472 KiB
38Wrong answer3ms4452 KiB
39Wrong answer2ms4444 KiB
40Wrong answer2ms4448 KiB
41Wrong answer3ms4684 KiB
42Wrong answer3ms4448 KiB
43Wrong answer3ms4616 KiB
44Wrong answer3ms4472 KiB
45Wrong answer3ms4476 KiB
46Wrong answer3ms4484 KiB
47Wrong answer3ms4484 KiB
48Wrong answer3ms4480 KiB
49Wrong answer3ms4632 KiB
50Wrong answer3ms4484 KiB
51Wrong answer3ms4588 KiB
52Wrong answer3ms4488 KiB
53Wrong answer3ms4632 KiB
54Wrong answer3ms4604 KiB
55Wrong answer3ms4688 KiB
56Wrong answer3ms4580 KiB
57Wrong answer3ms4536 KiB
58Wrong answer3ms4724 KiB