#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 << " ";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1832 KiB | ||||
2 | Wrong answer | 4ms | 2772 KiB | ||||
subtask2 | 0/11 | ||||||
3 | Wrong answer | 3ms | 2264 KiB | ||||
4 | Wrong answer | 3ms | 2460 KiB | ||||
5 | Accepted | 3ms | 2668 KiB | ||||
6 | Accepted | 3ms | 2872 KiB | ||||
7 | Wrong answer | 3ms | 3552 KiB | ||||
8 | Accepted | 3ms | 3636 KiB | ||||
subtask3 | 6/6 | ||||||
9 | Accepted | 4ms | 4100 KiB | ||||
10 | Accepted | 4ms | 4044 KiB | ||||
11 | Accepted | 4ms | 3988 KiB | ||||
subtask4 | 14/14 | ||||||
12 | Accepted | 4ms | 4268 KiB | ||||
13 | Accepted | 4ms | 4184 KiB | ||||
subtask5 | 0/23 | ||||||
14 | Wrong answer | 4ms | 4176 KiB | ||||
15 | Wrong answer | 4ms | 4420 KiB | ||||
subtask6 | 0/19 | ||||||
16 | Wrong answer | 3ms | 4344 KiB | ||||
17 | Accepted | 4ms | 4504 KiB | ||||
18 | Wrong answer | 4ms | 4500 KiB | ||||
19 | Wrong answer | 3ms | 4480 KiB | ||||
20 | Wrong answer | 3ms | 4716 KiB | ||||
21 | Wrong answer | 3ms | 4544 KiB | ||||
22 | Wrong answer | 3ms | 4632 KiB | ||||
23 | Wrong answer | 3ms | 4632 KiB | ||||
24 | Wrong answer | 4ms | 4764 KiB | ||||
subtask7 | 0/27 | ||||||
25 | Accepted | 3ms | 4836 KiB | ||||
26 | Wrong answer | 4ms | 5028 KiB | ||||
27 | Wrong answer | 4ms | 5360 KiB | ||||
28 | Wrong answer | 4ms | 5748 KiB | ||||
29 | Wrong answer | 4ms | 6316 KiB | ||||
30 | Wrong answer | 9ms | 9624 KiB | ||||
31 | Wrong answer | 4ms | 5664 KiB | ||||
32 | Wrong answer | 4ms | 5728 KiB | ||||
33 | Wrong answer | 4ms | 5724 KiB | ||||
34 | Wrong answer | 4ms | 5960 KiB | ||||
35 | Wrong answer | 3ms | 5600 KiB | ||||
36 | Wrong answer | 4ms | 5916 KiB | ||||
37 | Accepted | 3ms | 5456 KiB | ||||
38 | Wrong answer | 3ms | 5596 KiB | ||||
39 | Wrong answer | 6ms | 7280 KiB | ||||
40 | Wrong answer | 3ms | 5192 KiB | ||||
41 | Wrong answer | 3ms | 4928 KiB | ||||
42 | Wrong answer | 4ms | 5436 KiB | ||||
43 | Wrong answer | 4ms | 5384 KiB |