53712023-04-26 19:21:24gortomiZárójelekcpp17Wrong answer 0/10010ms9492 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 << " ";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1828 KiB
2Wrong answer4ms2616 KiB
subtask20/11
3Wrong answer3ms2112 KiB
4Wrong answer3ms2324 KiB
5Wrong answer3ms2540 KiB
6Wrong answer3ms2744 KiB
7Wrong answer3ms3708 KiB
8Accepted3ms3660 KiB
subtask30/6
9Wrong answer4ms3988 KiB
10Accepted4ms3980 KiB
11Accepted4ms4244 KiB
subtask40/14
12Wrong answer4ms4552 KiB
13Wrong answer4ms4836 KiB
subtask50/23
14Wrong answer4ms4624 KiB
15Wrong answer4ms4600 KiB
subtask60/19
16Wrong answer3ms4576 KiB
17Wrong answer3ms4764 KiB
18Wrong answer4ms4752 KiB
19Wrong answer4ms4648 KiB
20Wrong answer3ms4704 KiB
21Wrong answer3ms4672 KiB
22Wrong answer3ms4876 KiB
23Wrong answer3ms4824 KiB
24Wrong answer3ms4916 KiB
subtask70/27
25Accepted3ms4884 KiB
26Wrong answer4ms4992 KiB
27Wrong answer4ms5360 KiB
28Wrong answer4ms5476 KiB
29Wrong answer4ms6128 KiB
30Wrong answer10ms9492 KiB
31Wrong answer4ms5392 KiB
32Wrong answer4ms5384 KiB
33Wrong answer4ms5304 KiB
34Wrong answer4ms5396 KiB
35Wrong answer3ms5104 KiB
36Wrong answer4ms5468 KiB
37Accepted3ms5108 KiB
38Wrong answer3ms5280 KiB
39Wrong answer6ms7104 KiB
40Wrong answer3ms5216 KiB
41Wrong answer3ms4848 KiB
42Wrong answer3ms5312 KiB
43Wrong answer3ms5256 KiB