53722023-04-26 19:22:15gortomiZárójelekcpp17Wrong answer 20/1009ms9624 KiB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i = 0; i < n; i++) cin >> s[i];
    vector<pair<int, int> > v1, v2;
    vector<int> t(n);
    int sum = 0;
    for(int i = 0; i < n; i++)
    {
        int act = 0, mini = 0;
        for(auto x : s[i])
        {
            if(x == '(') act++;
            else act--;
            mini = min(mini, act);
        }
        mini *= -1;
        if(act > 0)
        {
            v1.push_back({mini, i});
            t[i] = act;
        }
        else
        {
            v2.push_back({mini + act, i});
            t[i] = -act;
        }
        sum += act;
    }
    if(sum != 0)
    {
        cout << "-1";
        return 0;
    }
    int cur = 0;
    vector<int> ans1, ans2;
    for(auto x : v1)
    {
        if(x.first > cur)
        {
            cout << "-1";
            return 0;
        }
        int y = x.second;
        ans1.push_back(y);
        cur += t[y];
    }
    cur = 0;
    for(auto x : v2)
    {
        if(x.first > cur)
        {
            cout << "-1";
            return 0;
        }
        int y = x.second;
        ans2.push_back(y);
        cur += t[y];
    }
    for(auto x : ans1) cout << x + 1 << " ";
    reverse(ans2.begin(), ans2.end());
    for(auto x : ans2) cout << x + 1 << " ";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Wrong answer4ms2772 KiB
subtask20/11
3Wrong answer3ms2264 KiB
4Wrong answer3ms2460 KiB
5Accepted3ms2668 KiB
6Accepted3ms2872 KiB
7Wrong answer3ms3552 KiB
8Accepted3ms3636 KiB
subtask36/6
9Accepted4ms4100 KiB
10Accepted4ms4044 KiB
11Accepted4ms3988 KiB
subtask414/14
12Accepted4ms4268 KiB
13Accepted4ms4184 KiB
subtask50/23
14Wrong answer4ms4176 KiB
15Wrong answer4ms4420 KiB
subtask60/19
16Wrong answer3ms4344 KiB
17Accepted4ms4504 KiB
18Wrong answer4ms4500 KiB
19Wrong answer3ms4480 KiB
20Wrong answer3ms4716 KiB
21Wrong answer3ms4544 KiB
22Wrong answer3ms4632 KiB
23Wrong answer3ms4632 KiB
24Wrong answer4ms4764 KiB
subtask70/27
25Accepted3ms4836 KiB
26Wrong answer4ms5028 KiB
27Wrong answer4ms5360 KiB
28Wrong answer4ms5748 KiB
29Wrong answer4ms6316 KiB
30Wrong answer9ms9624 KiB
31Wrong answer4ms5664 KiB
32Wrong answer4ms5728 KiB
33Wrong answer4ms5724 KiB
34Wrong answer4ms5960 KiB
35Wrong answer3ms5600 KiB
36Wrong answer4ms5916 KiB
37Accepted3ms5456 KiB
38Wrong answer3ms5596 KiB
39Wrong answer6ms7280 KiB
40Wrong answer3ms5192 KiB
41Wrong answer3ms4928 KiB
42Wrong answer4ms5436 KiB
43Wrong answer4ms5384 KiB