5371 2023. 04. 26 19:21:24 gortomi Zárójelek cpp17 Wrong answer 0/100 10ms 9492 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 << " ";
    reverse(ans2.begin(), ans2.end());
    for(auto x : ans2) cout << x << " ";
}
Subtask Sum Test Verdict Time Memory
subtask1 0/0
1 Wrong answer 3ms 1828 KiB
2 Wrong answer 4ms 2616 KiB
subtask2 0/11
3 Wrong answer 3ms 2112 KiB
4 Wrong answer 3ms 2324 KiB
5 Wrong answer 3ms 2540 KiB
6 Wrong answer 3ms 2744 KiB
7 Wrong answer 3ms 3708 KiB
8 Accepted 3ms 3660 KiB
subtask3 0/6
9 Wrong answer 4ms 3988 KiB
10 Accepted 4ms 3980 KiB
11 Accepted 4ms 4244 KiB
subtask4 0/14
12 Wrong answer 4ms 4552 KiB
13 Wrong answer 4ms 4836 KiB
subtask5 0/23
14 Wrong answer 4ms 4624 KiB
15 Wrong answer 4ms 4600 KiB
subtask6 0/19
16 Wrong answer 3ms 4576 KiB
17 Wrong answer 3ms 4764 KiB
18 Wrong answer 4ms 4752 KiB
19 Wrong answer 4ms 4648 KiB
20 Wrong answer 3ms 4704 KiB
21 Wrong answer 3ms 4672 KiB
22 Wrong answer 3ms 4876 KiB
23 Wrong answer 3ms 4824 KiB
24 Wrong answer 3ms 4916 KiB
subtask7 0/27
25 Accepted 3ms 4884 KiB
26 Wrong answer 4ms 4992 KiB
27 Wrong answer 4ms 5360 KiB
28 Wrong answer 4ms 5476 KiB
29 Wrong answer 4ms 6128 KiB
30 Wrong answer 10ms 9492 KiB
31 Wrong answer 4ms 5392 KiB
32 Wrong answer 4ms 5384 KiB
33 Wrong answer 4ms 5304 KiB
34 Wrong answer 4ms 5396 KiB
35 Wrong answer 3ms 5104 KiB
36 Wrong answer 4ms 5468 KiB
37 Accepted 3ms 5108 KiB
38 Wrong answer 3ms 5280 KiB
39 Wrong answer 6ms 7104 KiB
40 Wrong answer 3ms 5216 KiB
41 Wrong answer 3ms 4848 KiB
42 Wrong answer 3ms 5312 KiB
43 Wrong answer 3ms 5256 KiB